Reputation: 21206
I thought domain driven design is saying the Get-methods are in the Repositories and the Add/Del/Update are in the business objects?
Can you clarify this please?
When I look at the MVCMusicStore sample all CRUD methods to the database are in the entities ?!
Upvotes: 1
Views: 461
Reputation: 28131
Here's what a typical repository looks like:
public class OrderRepository {
public MyClass Load(Guid id); // throws an exception if not found
public void Save(Order order);
public void Delete(Guid id); // does not throw an exception if not found (idempotent)
}
Upvotes: 0
Reputation: 70701
The link you posted isn't an example of domain-driven design, it simply illustrates the MVC pattern. As you mentioned, the entities contain all persistence logic while the business logic lies primarily in the controllers.
In a domain-driven design of the same system, entities would not contain any persistence logic but they would contain most of the business logic. All persistence functions would reside in repositories, and the controllers (a.k.a. services) would be extremely thin and delegate most of the work to entities.
Upvotes: 2
Reputation: 17774
I've just answered a similar question could domain models be aware of repositories? (and also Does "Save" method belong to the Business Domain Entity? ) - and it seems that many many DDD questions are about Active Record vs. Repository choice.
I'd follow Eric Evans advice
In general, don't fight your frameworks. Seek ways to keep the fundamentals of DDD and let go the specifics when the framework is antagonistic. Look for affinities between the concepts of DDD and the concepts of the framework. This is assuming that you have no choice but to use the framework.
So, even if the creator of DDD is aware of some possible inconveniences, for me the choice between Active Record and Repository depends on the current stack of technologies.
Upvotes: 2