Language: EN

plantillas-clean-architecture-csharp

Clean Architecture Templates in C# and .NET Core

CleanArchitecture is a series of templates developed by Jason Taylor that facilitates the implementation of Clean Architecture in .NET applications.

Clean Architecture is a software architecture style that emphasizes the separation of concerns and the independence of system layers.

The architecture focuses on two main layers: Domain and Application, collectively known as the Core of the system.

Principles of Clean Architecture

  • Framework Independence: The system does not depend on any specific framework.
  • Testability: The absence of external dependencies in the Core facilitates automated testing.
  • UI Independence: The logic is separated from the UI, allowing for easy changes to frontend technologies.
  • Database Independence: Data access logic is decoupled, making it easier to migrate between different database technologies.
  • Independence from anything external: The Core is completely isolated from the outside world, ensuring its longevity and flexibility.

CleanArchitecture provides an organized structure for developing .NET applications, promoting the separation of concerns and scalability.

Clearly, it is not a project template for ALL projects. In fact, it is somewhat overkill for both large and small programs.

clean-arquitecture-alig

But it is interesting for getting ideas, especially if you are just starting. Or in general, to get ideas on how functional applications can be made (even though it’s not necessarily the easiest or most practical way).

For more details and examples, visit the CleanArchitecture repository on GitHub and explore how this library can help you implement a clean architecture in your .NET projects.

Installation and Configuration

To start using the CleanArchitecture templates in a .NET project, follow these steps for installation and configuration:

dotnet new install Clean.Architecture.Solution.Template

Now we use one of the templates to create a project. For example,

dotnet new ca-sln -cf React -o YourProjectName

Finally, we run the project with,

dotnet run

It’s that easy to have everything set up and ready to start,

csharp-clean-arquitecture-demo

Solution Structure

The template generates a multi-project solution with the following structure:

src
├── YourProjectName.Domain
├── YourProjectName.Application
├── YourProjectName.Infrastructure
└── YourProjectName.WebUI
tests
└── YourProjectName.Tests
  • Core: Contains the domain logic and types, such as entities, enums, exceptions, and interfaces. It has no external dependencies.
  • Application: Contains the business logic and uses CQRS (Command Query Responsibility Segregation). It defines interfaces that are implemented in external layers. It depends on the Domain project.
  • Infrastructure: Implements classes to access external resources, such as file systems and web services, based on interfaces defined in Application.
  • WebUI: Is the presentation layer, a SPA (Single Page Application) based on Angular and ASP.NET Core. It depends on the Application and Infrastructure projects.

Technologies Used

In addition to .NET, the solution uses the following technologies: