Onion / Clean Architecture in .NET: project references and dependency inversion (diagram)

Difference from N-tier: in N-tier the BLL points to the DAL.

text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# ======================================================================
# Q: Explain Onion / Clean Architecture. How do the projects reference each
# other?
#
# - Difference from N-tier: in N-tier the BLL points to the DAL. Here
#   Infrastructure points to Application (dependency inversion). The database is
#   a detail.
# - Onion vs Clean: practically the same. Clean explicitly names the use cases
#   (handlers) and the "interface adapters".
# - Enforce the rules with architecture tests, so that nobody (not even an AI
#   agent) puts EF Core into the Domain.
# ======================================================================

  +-------------------------------------------------+
  |  Api / UI                    Infrastructure     |   outer: ASP.NET, EF Core, HTTP
  |   +-----------------------------------------+   |
  |   |  Application (use cases, interfaces)    |   |
  |   |   +---------------------------------+   |   |
  |   |   |  Domain (entities, value objs)  |   |   |   core: no dependencies
  |   |   +---------------------------------+   |   |
  |   +-----------------------------------------+   |
  +-------------------------------------------------+
  All dependencies point inward.

Shop.Domain          → nothing (no EF Core, no ASP.NET)
Shop.Application     → Shop.Domain
Shop.Infrastructure  → Shop.Application      (implements its interfaces)
Shop.Api             → Shop.Application + Shop.Infrastructure (only for DI)