Search code examples
domain-driven-designonion-architecture

Onion Architecture - what are the layers and where to place the services?


I am learning and working out a sample project applying onion architecture and domain driven design.

As per my understanding I have drafted a small presentation and attached as an image in this post.

I need clarifications on layers of onion architecture and its implementation. Could you explain based on my presentation?

enter image description here

Core Project:

Domain Layer - entities, value objects, aggregate root, domain exception objects.

Domain Service Layer - business logic contracts.

Infrastructure Service Layer - persistence contracts, repository contracts, email and sms contracts, domain events and integration events contracts.

Application Service Layer - orchestration of infrastructure and domain service interfaces for uses cases.

Indentity Project:

Web Api Layer - controllers, configuration, composition root etc.

Infrastructure Layer - persistence implementation, repository implementation, email and sms implementation, message queuing etc.

Where would I implement contracts of the domain service layer from core project?


Solution

  • The Onion architecture is cut into these layers :

    • The core contains the business rules (in DDD, the Domain Model).
    • Around the core there is the Application layer.
    • Around the Application layer there is Port (IHM, REST...) and Adapter layer (Persistence, Messaging...).

    In your exemple, you have two projects, each project is an onion with all layers.

    In addition, don't forget to design/cut your Subdomains with the business expert views. Technical considerations are not a good way for this.