Reputation: 2445
Probably a stupid question:
Domain entities should be completely unaware of Persistence layer and as such should communicate with it only through Repositories, thus Domain entities should be Persistence Ignorant.
Common way of completely decoupling Domain layer from Persistence layer is by using Repositories, where Repository interfaces live within the Domain assembly, while the Respository implementations exist within the Persistence layer assembly PLA.
But I'm a bit confused about the terminology. Namely,I know it is a bad idea to put Repository interface inside PLA for at least two reasons, first reason being that this forces Domain assembly to hold a reference to PLA, and also now Repository interface is defined in terms of lower level components ( ie now Persistence layer dictates the definition of a Repository interface ). But if for whatever reason we did put Repository interface inside PLA,then:
a) could we still argue that Domain layer ( ie its entities ) is Persistent Ignorant? I'd assume yes, since domain entities are still completely unaware of Persistence layer?!
b) would in such situation the correct expression be that "Domain assembly now depends on PLA" or perhaps that "Domain layer now depends on Persistence layer" or...?
Thank you
Upvotes: 0
Views: 272
Reputation: 101150
a) could we still argue that Domain layer ( ie its entities ) is Persistent Ignorant? I'd assume yes, since domain entities are still completely unaware of Persistence layer?!
The domain entities is still unaware of the persistence layer (as long as they use the interfaces). The assembly however is dependent of the persistence layer.
b) would in such situation the correct expression be that "Domain assembly now depends on PLA" or perhaps that "Domain layer now depends on Persistence layer" or...?
Doesn't really matter. The purpose of the repository interfaces is to abstract away data layer and make the domain model 100% persistence ignorant.
The typical mistake that new DDD users do is to model the domain model after the database (i.e. create the DB first and then try to fit the domain model after it) instead of vice versa.
Upvotes: 1
Reputation: 14064
a) It's not uncommon at all that Domain layer Services (and even entities, occasionally) need to get data from Repositories. So practically speaking, placing your repository interfaces in the persistence layer will break PI more often than not.
b) I guess you could say both.
Upvotes: 0