SaranArjun
2 min readMay 3, 2024

In 2024, the principles of Clean Architecture in C# ASP.NET Core remain largely consistent, emphasizing separation of concerns, testability, and maintainability. However, there might be some advancements or refinements in techniques and folder structures. Here’s an updated approach you might consider:

Techniques:

  1. Dependency Injection (DI): Continue leveraging the built-in DI container in ASP.NET Core for managing dependencies.
  2. Middleware Pipeline: Utilize middleware for cross-cutting concerns like logging, exception handling, and authentication.
  3. Async Programming: Embrace asynchronous programming for better scalability and responsiveness.
  4. Entity Framework Core: If using a database, consider Entity Framework Core for data access, providing a convenient ORM solution.
  5. Unit Testing: Employ unit testing frameworks like xUnit or NUnit for writing automated tests to ensure code quality.
  6. Containerization: If applicable, containerize your ASP.NET Core application using Docker for easier deployment and scalability.
  7. Continuous Integration/Continuous Deployment (CI/CD): Implement CI/CD pipelines for automated testing and deployment.

Folder Structure:

  1. Presentation Layer:
  • Controllers: Handle HTTP requests and orchestrate the flow of data.
  • ViewModels or DTOs: Define models specific to views or APIs.
  • Views (if using MVC): UI components for rendering HTML.
  • wwwroot: Static files like CSS, JavaScript, and client-side assets.

2. Application Layer:

  • Services: Contain business logic and act as an abstraction layer between the presentation and domain layers.
  • Mappers: Convert between different data transfer objects (DTOs) and domain entities.

3. Domain Layer:

  • Entities: Represent domain objects.
  • Repositories/Interfaces: Define interfaces for data access operations.
  • Exceptions: Custom exception types specific to the domain.

4. Infrastructure Layer:

  • Data: Implement data access logic, including Entity Framework Core DbContext and migrations.
  • Repositories: Implement interfaces defined in the domain layer for data access.
  • External Services: Wrappers or clients for external services like APIs or message queues.
  • Logging: Implement logging mechanisms, integrating with ASP.NET Core logging framework.

5. Cross-cutting Concerns:

  • Middleware: Global concerns like logging, exception handling, and authentication.
  • Filters: Implement action filters for handling repetitive cross-cutting concerns like logging, validation, etc.

6. Tests:

  • Unit Tests: For testing individual components like services, repositories, and controllers.
  • Integration Tests: Test interactions between components and external dependencies.
  • UI Tests (if applicable): Automated tests for UI components.

7. Utilities (if necessary):

  • Helper Classes: Utility classes or extension methods used across the application.
  • Constants/Enums: Define constants and enumerations used throughout the application.

This structure helps maintain a clear separation of concerns, making the application easier to understand, test, and maintain. Adjustments can be made based on specific project requirements and team preferences.