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 is cleaner.

So is the onion architecture indeed better in all aspects and 3 layered architecture is just an old way of doing things, or there are some scenarios where I should prefer to use the 3 layered architecture, if so - which?


1 Answer 1


Layers, Onions, Ports, Adapters: it's all the same

Since this article makes clear that onion is equivalent to 3 layer + application of the Dependency Inversion Principle (DIP), then the question becomes "where should I prefer to use DIP?" I'd say any non-toy project. Using DIP allows the core of your code to be more isolated, testable and maintainable. When you really don't care about that is when it's a throw-away project or when you are trading maintainability for performance.

Also, don't confuse DIP with DI (Dependency Injection) containers. One doesn't imply the other.

  • From the Layers, Onions ... link above, I don't understand how the UI will retrieve some domain entities without Data Access Library. For example, let's consider Person Domain. To obtain a list of people from UI, don't we need the Data Access Library? That means UI is dependent on Data Access Library. No?
    – bostonjava
    Apr 23, 2020 at 17:04
  • @bostonjava The idea behind dependency inversion is for the dependency to be the other way around. The Person domain defines the data structure, and the DAL depends on that and loads data into it. But the Person domain doesn't know anything about it and basically takes no side effect dependencies. App/infrastructure services are responsible for organizing side effects like loading from DB and invoking domain behaviors. Since the core business code has no outside entanglements, it is easier to test and maintain. Jul 8, 2020 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.