To answer your question in the context of an application...
Your example is that of a Model1. Its properties are public because:
By convention, public properties with a getter and a setter will be included in the model.2
In general, properties are public (or protected, or internal) and fields are private.
A property is meant to be exposed in some way. For example, a Model exposes some properties.
A private field is suitable for a dependency. For example, in ProductController
3 from linked repo:
public class ProductController : Controller {
private IProductRepository repository;
// ...
public ViewResult List(int page = 1) {
// Use repository, only in ProductController
// ...
}
}
References
- https://learn.microsoft.com/en-us/ef/core/modeling/
- https://learn.microsoft.com/en-us/ef/core/modeling/included-properties
- https://github.com/Apress/pro-asp.net-core-mvc/blob/ecbc7336cc9b4adb05825e8a0a355f3089fa4f0a/Source%20Code%201-31/08%20-%20SportsStore/SportsStore/src/SportsStore/Controllers/ProductController.cs
P.S. Questions on "general software engineering principles" risk getting closed as primarily opinion-based. See this Stack Overflow help topic: How do I ask a good question?