Secret ingredients to quality software

Do You Use a Dependency Injection Centric Architecture?

Last updated by Tiago Araujo on 17 Feb 2021 07:51 pm (6 months ago) See History

The classes in each layer can depend on layers toward the center.

It emphasizes the use of interfaces for the business logic and repository layers. The repository layer corresponds to the Data Access Layer in an n-Tier architecture.

An n-Tier architecture has at its base the database.

The core of the onion architecture is the Domain Model, and all dependencies are injected. This leads to more maintainable applications since it emphasizes the separation of concerns.

dependency injection bad
Figure: Bad Example – N-Tiered architectures do not inherently support dependency injection

dependency injection good
Figure: Good Example – The Onion Architecture promotes layers built on interfaces, and then injecting dependencies into those layers. This keeps coupling low, and therefore maintainability high

Related rules

Adam StephensenAdam Stephensen
Igor GoldobinIgor Goldobin

We open source. This page is on GitHub