Questions tagged [onion-architecture]

The *Onion Architecture* is a software architecture proposed by Jeffrey Palermo. It is similar to the *Hexagonal Architecture* (Ports and Adapters) proposed by Alistair Cockburn.

Jeffrey Palermo proposed the Onion Architecture. It is similar to Alistair Cockburn's Hexagonal Architecture or Ports and Adapters.

The fundamental motivation of the approach is to avoid layer-to-layer dependencies usually associated with the N-tier architecture approach. This is achieved by placing all infrastructure, including databases, outside the problem domain.

According to Jeffrey Palermo:

The overall philosophy of the Onion Architecture is to keep your business logic and model in the middle (Core) of your application and push your dependencies as far outward as possible.

The problem domain is then completely independent of the required infrastructure (testing, databases, security, etc.). For example, this means that testing database accesses can be done thoroughly without a real database.

72 questions
131
votes
7 answers

Clean Architecture: Use case containing the presenter or returning data?

The Clean Architecture suggests to let a use case interactor call the actual implementation of the presenter (which is injected, following the DIP) to handle the response/display. However, I see people implementing this architecture, returning the…
75
votes
11 answers

Is it really possible to decouple the UI from the business logic?

I'm reading about software architectures like Hexagonal architecture, Onion architecture etc. They put a big emphasis on decoupling. The business logic sits at the centre and the UI sits on the outside. The idea is that the UI should not touch the…
MSOACC
  • 925
  • 1
  • 6
  • 11
20
votes
2 answers

What data should a repository return

I have a simple project where the controller calls the service, and the service calls the repository in order to get the needed data. Assuming that we have these domain models: // this model has a RepositoryA built for it Class A { public string…
Uentee
  • 391
  • 2
  • 4
  • 9
14
votes
1 answer

Onion architecture vs 3 layered architecture

I see only benefits to the onion architecture over the 3 layered architecture where the BL had responsibility to call methods on DAL (or an interface of DAL) to do CRUD. The onion has better separation of concerns, testability, maintainability and…
BornToCode
  • 1,273
  • 2
  • 13
  • 16
11
votes
2 answers

Where should you validate the state of "other" aggregates?

Scenario: A customer places an order, then, after receiving the product, provides feedback on the order process. Assume the following aggregate roots: Customer Order Feedback Here are the business rules: A customer can only provide feedback on…
10
votes
1 answer

Error handling in Nest service layer

I would like to create a REST API with NestJs. But I want to add GraphQL as another top level layer later on. So for the start I have the basic layers controller, service and TypeORM repository. Let's assume you want to update a user's username by…
10
votes
4 answers

Lookup Tables: Are they a leak in the domain model?

You are building a system that keeps track of Companies. Those companies have Contacts. Those contacts are often specialists that only answer certain types of questions, such as Billing/Payment, Sales, Ordering, and Customer Support. Using Domain…
Drew
  • 221
  • 2
  • 7
9
votes
2 answers

What are application and domain services in onion architecture?

Onion architecture has a core which is composed by domain model, domain services and application services: I'm in doubt about those two service layers, domain services and application services. I've been reading that they're related to DDD but I'm…
Piovezan
  • 449
  • 4
  • 13
9
votes
2 answers

How to structure an Onion project

Here is an example implementation using Onion architecture: https://www.codeproject.com/Articles/1028481/Understanding-Onion-Architecture The webpage suggests a solution structure of: Domain - Solution Folder Domain.Entities - Class Library…
w0051977
  • 7,031
  • 6
  • 59
  • 87
8
votes
2 answers

Avoiding Repository pattern - implementing Onion Architecture with DbContext only

I am trying to follow the Onion Architecture to design my application where I have the following layers - Domain Layer: is the inner-most layer and defines repository interfaces Infrastructure Layer: forms the outer-most layer peered with the…
8
votes
1 answer

Where should I place configuration classes in Onion Architecture

We are redesigning one of our API projects from an n-layered architecture into onion architecture. In the previous design, we had configuration classes in a common library project being referenced across all the layers (UI, Logic and Data Access…
InstilledBee
  • 91
  • 1
  • 6
7
votes
2 answers

What layer do third party API request/response models go in and what do you call them?

I have a RESTful API service that has three layers: Application/Domain, Infrastructure, and Presentation. Application/Domain contain my interfaces and models. I currently have three different types of models: DTO - These are the models my…
6
votes
3 answers

Where to convert primitive types in meaningful types in Clean Architecture / Onion Architecture

The book "Implementing Domain Driven Design" (page 361) suggests to use special types to distinguish several kinds of IDs, e. g. using BookId(1) instead of just 1 of type Int or Long. In my Clean Architecture or Onion Architecture the outermost…
6
votes
2 answers

Application service - part of Bounded Context?

I am having a hard time understanding where the Application Services fit in with DDD and Onion architecture. Up until a few days ago I thought of them as part of domain model, but I began to question that. I know what Application Services are…
robotron
  • 767
  • 1
  • 6
  • 14
6
votes
3 answers

Onion architecture: layer placement of business logic

Where should the business logic for a project that utilizes Onion Architecture be placed? In my case, it's a C#-based project, utilizing Web API and possibly a MVC UI for the presentation. But that may not matter, since I'm just curious about…
Adam Plocher
  • 347
  • 3
  • 11
1
2 3 4 5