Domain Driven Design series: Repository
Domain object does not have any access to any persistence object, remember the term Persistence Ignorance? How do the domain objects make use of persistence object then? Domain object can access the persistence object through repository interface. And the implementation of the repository interface will be handle by Infrastructure layer. What are in the infrastructure layer? There are some repository object, which are implement all repository interface in domain layer.
What kind of method usually reside in the repository object? Based on my experience, I always put the following method in the repository object.
- List<[DomainClass]> list[DomainName]Data,
- List<[DomainClass]> list[DomainName]DataByCriteria,
- [DomaiClass] get[Domain]ById,
- [DomainClass] get[Domain]ByCriteria,
- boolean is[Domain]Exist
Those method stated above will be implemented in the Infrastructure Layer. Hibernate ORM normally is used in the implementation of repository interfaces.
In the Spring application context, modify the xml:
<bean name="repositoryImplementationClass" class="SomeRepositoryImplementationClass">
</bean>
How to use those method in the presentation layer? Spring framework will handle the Dependency Injection. In the presentation class, just add:
DomainNameRepository domainService = null;
and create its getter and setter method.
In the Spring application context xml configuration, modify the file xml code
<bean name="presentationEditor" class="SomePresentationLayerClass">
<property name="domainService" ref="repositoryImplementationClass"/>
</bean>