Or should I always get my entities via service methods?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Most of the time I try to separate my layers as much as possible. Usually I’ll have my services act as facades to the business logic. Within business logic I use a DI Container, like Unity, to resolve my repositories…
Example:
My business logic contains no dependencies now on my infrastructure layer (repositories). For a great Repository implementation take a look at NCommon. Ritesh Rao wrote some great examples of pattern usage for DDD.
Whether it’s wrong to reference your repositories is subjective. I think DDD purists will tell you it most likely is. “How much SoC are you trying to achieve” is the real question. It’s usually best to strive for high cohesion via loose coupling, but sometimes that can be overkill.
Hope this helps.
[EDITED]
Repositories can exist within the domain. Really they sit in between your business logic / model and your infrastructure model. You are correct to depend on the interface not implementation.
Look at Martin Fowler’s – Separated Interface Pattern. In my above example I depend on the interface. The DI container resolves the actual implementation of my concrete repository class. Here is a sample DDD diagram I’ve been refining as I learn.
