Tutorials Clean Architecture & DDD Mastery
Onion Architecture: Dependency Inversion at the core
On this page
The Onion Pattern
Introduced by Jeffrey Palermo, Onion Architecture uses the Dependency Inversion Principle to ensure your domain logic is the center of your universe.
1. Layers of the Onion
- **Core (Domain):** Entities, Value Objects, and Domain Services.
- **In-Between (Application):** Interfaces (Abstractions) for the outside world.
- **Outer Ring (Infrastructure/UI):** Implementations of those interfaces (EF Core, Email Services, API Controllers).
2. The Dependency Rule
Dependencies always point **Inward**. The Core knows nothing about the Outer Rings. If the Business layer needs to save a user, it defines an IUserRepository interface. The Infrastructure layer then implements that interface. The Core stays pure and testable.
3. Architect Insight
Q: "Isn't this just more boilerplate?"
Architect Answer: "In the short term, yes. You'll write more interfaces and more projects. But in the long term, it's a lifecycle-saver. When Microsoft releases .NET 9 or you decide to move from SQL Server to PostgreSQL, you only change the **Outer Ring**. Your 10,000 lines of complex business logic in the Core remain completely untouched."