Re: Repository-interfaces: Domain Layer or Application Layer?

"[email protected] [domaindrivendesign]" <[email protected]>
Newsgroups gmane.comp.programming.domain-driven-design
Message-ID <[email protected]>
Long, 

 It's possible that you may need to use a repository in your Domain Layer. For example, a domain service may need to be injected with a repository to perform some specialized query, perhaps for performance considerations that you can't avoid. 
 

 On the other hand, you're less likely to need a repository in the domain layer when implementing CQRS because you should constrain yourself to only fetching aggregates by ID. Instead, you would fetch all aggregates involved in a business process at the application layer or use event-chaining or a saga to schedule read model lookups before sending another command.
 

 With that said, I actually create a common infrastructure project that contains mostly interfaces and some base classes. This common infrastructure project is where i maintain the interface(s) for my repositories. The common infrastructure project is referenced by the domain layer.
 

 App.Infrastructure - AggregateBase<TKey>, ValueObject<T>, IAggregateRepository<TAggregate>, IPublishEvents, etc
 

 App.Infrastructure.Persistence.Sql - Sql Implementation of AggregateRepository<TAggregate>
 

 App.Domain - Aggregates (inherit from AggregateBase<TKey>), Value Objects (inherit from ValueObject<T> which overrides equality operators)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.