DDD and EF Core: Preserving encapsulation
The whole point of Encapsulation and Separation of concerns is to reduce complexity The more coupling leads to an exponential growth of complexity With separation of concerns we can maintain the same number of elements but reduce the coupling or connections between them. Public setters in domain classes is a red flag. Setters prevent the class from maintaining invariants because this class has no control over how its clients use those setters. Always make property setters in domain classes private by default. Proper way to set up many-to-one relationships with EF Core with private constructor and reference to a the FavouriteCourse model: And with the mappings: The query to select the join: To reduce complexity and bugs, always load all entities whether they are required or not. This is called Eager loading of relationships. To add Lazy Loading, you need to add the following Avoid the use of explicit lazy loaders such as this...