Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD: Where to keep domain Interfaces, the Infrastructure?

Tags:

Does it make sense to group all Interfaces of your Domain Layer (Modules, Models, Entities, Domain Services, etc) all within the Infrastructure layer? If not, does it make sense to create a "shared" project/component that groups all of these into a shared library? After all, the definition of "Infrastructure Layer" includes "shared libraries for Domain, Application, and UI layers".

I am thinking of designing my codebase around the DDD layers: UI, Application, Domain, Infrastructure. This would create 4 projects respectfully. My point is, you reference the Infrastructure Layer from the Domain Layer. But if you define the interfaces in the Domain Layer project, say for IPost, then you'll have a circulur reference when you have to reference the Domain Layer project from the Infrastructure project when you are defining the IPostRepository.Save(IPost post) method. Hence, the idea of "define all Interfaces in the Shared library".

Perhaps the repositories should not expect an object to save (IPostRepository.Save(IPost post); but instead, expect the params of the object (that could be a long set of params in the Save() though). Given, this could be an ideal situation that shows when an object is getting overly complex, and additional Value Objects should be looked into for it.

Thoughts?

like image 525
eduncan911 Avatar asked Mar 28 '09 18:03

eduncan911


People also ask

What is Infrastructure layer in DDD?

The infrastructure layer is how the data that is initially held in domain entities (in memory) is persisted in databases or another persistent store. An example is using Entity Framework Core code to implement the Repository pattern classes that use a DBContext to persist data in a relational database.

What is Infrastructure layer?

The Infrastructure Layer is the data center building and the equipment and systems that keep it running. Components like back-up power equipment, the HVAC system, and fire suppression equipment are all part of the Infrastructure Layer. These devices and systems help protect servers and ultimately your data.

What is the full form of DDD with respect to microservice?

Domain-driven design (DDD) for building and decoupling microservices. Domain-driven design (DDD), first coined in a book by Eric Evans, is an approach used to build systems that have a complex business domain.

Where is domain Service implemented?

Place the implementation in domain layer. (Example: an order number that is calculated) If the implementation requires anything from application layer (for example it requires accessing the Aggregate repository which, in my opinion lives in Application layer), then place the implementation in the application layer.


1 Answers

Concerning where to put the repositories, personally I always put the repositories in a dedicated infrastructure layer (e.g . MyApp.Data.Oracle) but declare the interfaces to which the repositories have to conform to in the domain layer.
In my projects the Application Layer has to access the Domain and Infrastructure layer because it’s responsible to configure the domain and infrastructure layer.
The application layer is responsible to inject the proper infrastructure into the domain. The domain doesn’t know to which infrastructure it’s talking to, it only knows how to call it. Of course I use IOC containers like Structuremap to inject the dependencies into the domain. Again I do not state that this is the way DDD recommends to structure your projects, it’s just the way, I architecture my apps. Cheers.

like image 69
Geo Avatar answered Nov 11 '22 20:11

Geo