KEMBAR78
Clean Architecture in Dot Net | PDF | Databases | Software Architecture
0% found this document useful (0 votes)
38 views3 pages

Clean Architecture in Dot Net

Clean Architecture, proposed by Robert C. Martin, focuses on separation of concerns and independence from frameworks, UI, and databases to create maintainable and scalable software. It is structured into four layers: Domain, Application, Infrastructure, and Presentation, each with specific responsibilities and dependencies. The approach emphasizes easy testing, low coupling, and high cohesion, making it easier to replace infrastructure components.

Uploaded by

aufci615
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

Clean Architecture in Dot Net

Clean Architecture, proposed by Robert C. Martin, focuses on separation of concerns and independence from frameworks, UI, and databases to create maintainable and scalable software. It is structured into four layers: Domain, Application, Infrastructure, and Presentation, each with specific responsibilities and dependencies. The approach emphasizes easy testing, low coupling, and high cohesion, making it easier to replace infrastructure components.

Uploaded by

aufci615
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Clean Architecture in .

NET

Introduction

Clean Architecture, proposed by Robert C. Martin (Uncle Bob), emphasizes separation of concerns and
independence from frameworks, UI, and databases. It helps build maintainable, testable, and scalable
software.

Core Principles

• Independent of UI, database, or external frameworks


• Emphasizes the Dependency Rule: Dependencies point inward
• Focus on use cases and business rules

Layered Structure

1. Domain Layer: Core business logic and entities


2. Application Layer: Use cases, services, DTOs
3. Infrastructure Layer: Database, file system, email services
4. Presentation Layer: API controllers or UI

Project Structure Example

MyApp
├── MyApp.Domain
├── MyApp.Application
├── MyApp.Infrastructure
├── MyApp.API (or UI)

Domain Layer

• Contains Entities, Value Objects, Enums


• No dependencies on other layers

Application Layer

• Contains interfaces, use case logic, services


• Uses DTOs to avoid domain leakage
• Depends only on Domain

public interface IEmployeeService


{
Task<EmployeeDto> GetEmployeeByIdAsync(Guid id);
}

1
Infrastructure Layer

• Implements interfaces from Application Layer


• Injected via Dependency Injection

public class EmployeeService : IEmployeeService


{
// implementation
}

API Layer

• Contains Controllers
• Coordinates requests to Application Layer

[ApiController]
[Route("api/[controller]")]
public class EmployeesController : ControllerBase
{
private readonly IEmployeeService _service;
public EmployeesController(IEmployeeService service) => _service = service;

[HttpGet("{id}")]
public async Task<IActionResult> Get(Guid id) => Ok(await
_service.GetEmployeeByIdAsync(id));
}

Dependency Injection

Register implementations in the API project (e.g., Program.cs ):

builder.Services.AddScoped<IEmployeeService, EmployeeService>();

Mapping

Use AutoMapper to map between entities and DTOs:

CreateMap<Employee, EmployeeDto>();

Benefits

• Easy testing
• Low coupling, high cohesion

2
• Easy to replace infrastructure (e.g., switch from EF Core to Dapper)

Conclusion

Clean Architecture provides a solid foundation for scalable and maintainable software. By organizing
your .NET solution into layers, you can write testable and loosely coupled code that lasts.

Author: Gamal Kasem Farouk Date: July 2025 License: Free to Use

You might also like