0
votes

i have a this question, that i just cant get my head around it Right now, i am implementing a DDD architecture, in a .NET CORE project, i have created 3 layers, Application, Domain, Infrastructure, but there is a problem, on which i cant understand I have implemented the Repository Patterns and IUnitOfWork, but a question remains in my head The domain layer will do the business logic to the Data, but how is that Data going to be persisted in the DB? since the Domain layer cant have dependencies on infrastructure Will it send the data back to the Application and then Application layer sends to the infrastructure? Or will the Domain layer have a ApplicationDbContext file too, like Infrastructure Layer?

Here is a snippet of my Current Folder structure!:

enter image description here

1
This sounds more like a conceptual problem, not a coding problem. Did you check prior questions and answers in the ddd tag on SE.SE - rene
Yes it is, but still, i tought it could be answered by anyone, after all, this is a forum - filipe
checking it right now - filipe
Your domain project should depend on the interfaces of the repository, but not on the concrete implementations of those interfaces. It's the 'inversion of control' pattern. - Hans Kilian
yes, thank you for your response, i now that, but the problem is, how will the data that is applied all the logic in Domain. be persisted in the DB? Since the Domain cant be contaiminated by the Infrastructure - filipe

1 Answers

0
votes

Domain Layer usually contains enterprise logic and entities. Application Layer would have Interfaces and types. The main difference is that The Domain Layer will have the types that are common to the entire enterprise, hence can be shared across other solutions as well. But the Application Layer has Application-specific types and interfaces.

The Core Layers (Domain and Application) will never depend on any other layer. Therefore we create interfaces in the Application Layer and these interfaces get implemented in the external layers. This is also known as the Dependency Inversion Principle.

The Infrastructure Layer is where you would want to add your Infrastructure. Infrastructure can be anything. Maybe an Entity Framework Core Layer for Accessing the DB including DB Contexts and Identity and etc. Most of the project's dependencies on external resources should be implemented in classes defined in the Infrastructure project. These classes should implement interfaces defined in the Application layer.

The Application layer has a dependency on the Domain layer and the Infrastructure layer has a dependency on both Application and Domain layers. In my approach which I usually apply CQRS pattern, I implement the handlers of my queries and commands in the Application layer.

In order to get a better understanding of this matter, I recommend you to study Clean Architecture articles on the web.