Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD and implementing persistence

Tags:

I am getting my feet wet with DDD (in .Net) for the first time, as I am re-architecting some core components of a legacy enterprise application.

Something I want to clear up is, how do we implement persistence in a proper DDD architecture?

I realize that the domains themselves are persistence ignorant, and should be designed using the "ubiquitous language" and certainly not forced into the constraints of the DAC of the month or even the physical database.

Am I correct that the Repository Interfaces live within the Domain assembly, but the Respository Implementations exist within the persistence layer? The persistence layer contains a reference to the Domain layer, never vice versa?

Where are my actual repository methods (CRUD) being called from?

like image 883
EkoostikMartin Avatar asked Aug 23 '11 16:08

EkoostikMartin


People also ask

What is persistence infrastructure?

The persistence infrastructure uses façade-layer logic to translate data that is received from a user interface screen into a format suitable for passing into a service-layer API call.

What is persistence layer database?

The persistence layer of enterprise applications serves as an intermediary between the business functions of the application and the data it stores in a relational database. This function of the persistence layer is also known as object-relational mapping because it maps Java objects to relational data.

What is persistence domain model?

A domain model should always be concerned with domain BEHAVIOR, while a persistence model, at most, it stores domain object STATE. The persistence models what you want to store from an object and that data will be used to restore the object.

Is DDD a software architecture?

Modern Software Architecture with Domain Driven Design (DDD). Introduction on DDD and its relation to Microservices, Reactive Systems, BPM, Agile, CQRS and Event Sourcing. Welcome to the first issue on Modern Software Architecture.


1 Answers

Am I correct that the Repository Interfaces live within the Domain assembly, but the Repository Implementations exist within the persistence layer? The persistence layer contains a reference to the Domain layer, never vice versa?

Yes, this is a very good approach.

Where are my actual repository methods (CRUD) being called from?

It might be a good idea to not think in CRUD terms because it is too data-centric and may lead you into Generic Repository Trap. Repository helps to manage middle and the end of life for domain objects. Factories are often responsible for beginning. Keep in mind that when the object is restored from the database it is in its midlife stage from DDD perspective. This is how the code can look like:

// beginning 
Customer preferredCustomer = CustomerFactory.CreatePreferred();
customersRepository.Add(preferredCustomer);

// middle life
IList<Customer> valuedCustomers = customersRepository.FindPrefered();

// end life
customersRepository.Archive(customer);

You can call this code directly from you application. It maybe worth downloading and looking at Evan's DDD Sample. Unit of Work pattern is usually employed to deal with transactions and abstracting your ORM of choice.

like image 172
Dmitry Avatar answered Sep 21 '22 02:09

Dmitry