How nilavpatel/dotnet-onion-architecture works
This is a .NET 8 user-management REST API organized around the documented onion architecture. The principal workflow enters through the user controller, delegates create, validate, or active-user listing to the application service, and uses domain specifications and repository contracts to access persisted users. The repository and unit of work are implemented with Entity Framework; infrastructure also provides email and logging services. The README documents the broader layer responsibilities, while source-index references and excerpts support the specific calls and wiring shown here; unsampled behavior is not inferred.
Main entry points: UserService.cs User workflows · ServiceExtensions.cs Infrastructure registration · EmailService.cs Email service · BaseRepositoryAsync.cs Async repository
Components 25
Presentation
- User controller
src/MyApp.WebApi/Controllers/UserController.cs
Application
- User service contract
src/MyApp.Application/Interfaces/IUserService.cs - User workflows
src/MyApp.Application/Services/UserService.cs - User API models
src/MyApp.Application/Models - User DTO mapping
src/MyApp.Application/Models/DTOs/UserDTO.cs - Application registration
src/MyApp.Application/ServiceExtensions.cs - Email contract
src/MyApp.Application/Core/Services/IEmailService.cs - Email model
src/MyApp.Application/Core/Models/Email.cs - Logger contract
src/MyApp.Application/Core/Services/ILoggerService.cs
Domain
- User entity
src/MyApp.Domain/Entities/User.cs - User status
src/MyApp.Domain/Enums/UserStatus.cs - User specifications
src/MyApp.Domain/Specifications/UserSpecifications.cs - Repository contracts
src/MyApp.Domain/Core/Repositories - Specification contract
src/MyApp.Domain/Core/Specifications/ISpecification.cs - Base entity
src/MyApp.Domain/Core/Models/BaseEntity.cs
Infrastructure
- Async repository
src/MyApp.Infrastructure/Repositories/BaseRepositoryAsync.cs - Specification evaluator
src/MyApp.Infrastructure/Repositories/SpecificationEvaluator.cs - Unit of work
src/MyApp.Infrastructure/Repositories/UnitOfWork.cs - EF database context
src/MyApp.Infrastructure/Data/MyAppDbContext.cs - SQL Server database
- Infrastructure registration
src/MyApp.Infrastructure/ServiceExtensions.cs - Email service
src/MyApp.Infrastructure/Services/EmailService.cs - Logger service
src/MyApp.Infrastructure/Services/LoggerService.cs
Other components
- API client
- SMTP service
Connections 31
- API client → User controller: sends requests
src/MyApp.WebApi/Controllers/UserController.cs - User controller → User service contract: dispatches to
src/MyApp.WebApi/Controllers/UserController.cs - User workflows → User service contract: implements
src/MyApp.Application/Services/UserService.cs - User workflows → User API models: uses requests and responses
src/MyApp.Application/Services/UserService.cs - User workflows → User DTO mapping: maps users to
src/MyApp.Application/Services/UserService.cs - User workflows → Repository contracts: uses unit of work
src/MyApp.Application/Services/UserService.cs - User workflows → User specifications: builds queries with
src/MyApp.Application/Services/UserService.cs - User workflows → Logger contract: logs through
src/MyApp.Application/Services/UserService.cs - User specifications → User entity: specifies queries for
src/MyApp.Domain/Specifications/UserSpecifications.cs - User entity → User status: uses status
src/MyApp.Domain/Entities/User.cs - User entity → Base entity: inherits
src/MyApp.Domain/Entities/User.cs - Repository contracts → Base entity: constrains entities by
src/MyApp.Domain/Core/Repositories/IBaseRepositoryAsync.cs - Repository contracts → Specification contract: accepts specifications
src/MyApp.Domain/Core/Repositories/IBaseRepositoryAsync.cs - Async repository → Repository contracts: implements
src/MyApp.Infrastructure/Repositories/BaseRepositoryAsync.cs - Async repository → EF database context: queries and updates
src/MyApp.Infrastructure/Repositories/BaseRepositoryAsync.cs - Async repository → Specification evaluator: evaluates specifications with
src/MyApp.Infrastructure/Repositories/BaseRepositoryAsync.cs - Specification evaluator → Specification contract: evaluates
src/MyApp.Infrastructure/Repositories/SpecificationEvaluator.cs - Unit of work → Async repository: creates repositories
src/MyApp.Infrastructure/Repositories/UnitOfWork.cs - Unit of work → EF database context: saves through
src/MyApp.Infrastructure/Repositories/UnitOfWork.cs - EF database context → User entity: maps users
src/MyApp.Infrastructure/Data/MyAppDbContext.cs - EF database context → SQL Server database: persists data to
- Infrastructure registration → EF database context: configures
src/MyApp.Infrastructure/ServiceExtensions.cs - Infrastructure registration → Async repository: registers
src/MyApp.Infrastructure/ServiceExtensions.cs - Infrastructure registration → Unit of work: registers
src/MyApp.Infrastructure/ServiceExtensions.cs - Infrastructure registration → Email service: registers
src/MyApp.Infrastructure/ServiceExtensions.cs - Infrastructure registration → Logger service: registers
src/MyApp.Infrastructure/ServiceExtensions.cs - Email service → Email contract: implements
src/MyApp.Infrastructure/Services/EmailService.cs - Email service → Email model: sends
src/MyApp.Infrastructure/Services/EmailService.cs - Email service → SMTP service: sends mail through
src/MyApp.Infrastructure/Services/EmailService.cs - Email service → Logger contract: logs failures through
src/MyApp.Infrastructure/Services/EmailService.cs - Logger service → Logger contract: implements
src/MyApp.Infrastructure/Services/LoggerService.cs