locked
The correct method of implementing the clean architecture in asp core RRS feed

  • Question

  • User461962111 posted

    I have seen several ways to implement a clean architecture in the asp core environment.

    Some only used repositories, some use use cases, some use Cqrs, some use Uow, some use repositories with Mediatr, and so on.

    Sometimes it is said that Uow and repository are completely wrong and are anti-pattern, and sometimes there is a strong emphasis on using repository and Uow !!!!!!

    I could not reach a conclusion. Can anyone provide a summary and a small project example?

    Tuesday, May 25, 2021 9:02 AM

All replies

  • User475983607 posted

    asgharb

    Sometimes it is said that Uow and repository are completely wrong and are anti-pattern, and sometimes there is a strong emphasis on using repository and Uow !!!!!!

    There is nothing wrong with the Unit of Work pattern.  Entity Framework is a UoW pattern.  The problem occurs when developers try to wrap Entity Framework in another UoW pattern or generic repository.

    asgharb

    I could not reach a conclusion. Can anyone provide a summary and a small project example?

    It is not possible to answer your question or provide any meaningful code examples because you have not explained the application requirements or the programming problem you are trying to solve.  Architectures and programming patterns solve common problems.  Your question assumes there is a magical approach that works for every application which in not true.  Application are unique and made up of many programming patterns.

    Tuesday, May 25, 2021 10:26 AM
  • User-821857111 posted

    "Clean architecture" is a general term that indicates that you have applied separation of concerns to your project, and that it isn't full of code that is difficult to maintain or extend. All of the things you mentioned - UoW, Repository, CQRS etc are design patterns that provide solutions to specific problems. You should try to understand the specific design patterns that you listed, the problems that they solve, along with other perfectly valid solutions to the same problems, and then use them when necessary in your application. That way, you will have achieved a clean architecture.

    Tuesday, May 25, 2021 2:20 PM
  • User1686398519 posted

    Hi asgharb, 

    Clean architecture puts the business logic and application model at the center of the application.

    In a Clean Architecture solution, each project has clear responsibilities

    1. Application Core
      • The Application Core holds the business model, which includes entities, services, and interfaces.
    2. Infrastructure
      • The Infrastructure project typically includes data access implementations.
    3. UI Layer
      • The user interface layer in an ASP.NET Core MVC application is the entry point for the application.
      • This project should reference the Application Core project, and its types should interact with infrastructure strictly through interfaces defined in Application Core.

    You can click on the link to see a more detailed explanation.

    In addition, you can click this link to view the detailed example.

    Best Regards,

    YihuiSun

    Wednesday, May 26, 2021 1:51 AM
  • User-2054057000 posted

    Can anyone provide a summary and a small project example?

    See - Implementing ASP.NET Core CRUD Operation with CQRS and MediatR Patterns

    Monday, June 7, 2021 5:31 AM