Contents
Is the domain model allowed to depend on repository?
Domain model is not allowed to depend on repository and domain service is part of domain model -> domain service should not depend on repository. What you should do instead is assemble all your entities that are needed for business logic execution already in application service and then just provide your models with instantiated objects.
When to inject and use repository in domain service?
Notwithstanding the above, sometimes it is useful to inject and use a repository in a domain service, but only if your repositories are implemented such that they accept and return aggregate roots only, and also where you are abstracting logic that involves multiple aggregates. e.g.
Can a domain model have injectable dependencies?
A domain model and let’s extend that to any model in general, should not have injectable dependencies. A domain service (factory) is built inside the domain and is going to have constructor injection in any non-trivial software implementation.
What does rich domain model mean in CRUD?
Rich domain model = a collection of objects that expose behavior. If you want to create a simple CRUD application, maybe an anemic model with a classic MVC framework is enough. But if you want to implement some kind of logic, anemic model means that you will not do object oriented programming.
Is there another package for the repository inside the domain?
Inside the Domain, there is another package for the Repository (its interfaces and their implementations) The Service contains interfaces and their implementations BUT here, services implementation classes call Repository objects and kind of repeat their methods.
Can a domain service wrap a repository with persist?
But adding a domain service that wraps a repository with a method called persist adds little value. On that basis, if your application service is expressing a use case that calls for only working with a single aggregate, there is no problem using the repository directly from the application service.