Question about clean architecture

Hikljh Dima 20 Reputation points
2024-01-26T18:30:20.3033333+00:00

I read article about clean architecture (in microsoft docs) and I have question about validation. In the article said that Application layer must not have any dependencies from external libraries and frameworks. But I see examples projects on github which build within clean architecture and many projects use fluent validation library in Application layer. So I have confusion, if sense of this architecture make independence application (and domain) layers from frameworks - why people do this?

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | ASP.NET | ASP.NET API
Developer technologies | .NET | Other
Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2024-01-29T02:04:11.29+00:00

    Hi @Hikljh Dima, Based on my understanding, the clean architecture is to structure the code in a way that the business logic (core domain) is isolated from external concerns such as frameworks and libraries. While the Clean Architecture principles advocate for keeping the application layer free from dependencies on external libraries, it doesn't mean that you can't use any external libraries at all. It means we need concern the frameworks and libraries impact of the overall architecture. The fluent validation we could consider it works as a tool. You could also write the library to achieve the same thing inside the application layer. Clean architecture doesn't mean don't use any library. The mean goal is to keep the business logic isolated from the technical details and frameworks. If the use of a library is focused on technical concerns like validation or mapping, it might be acceptable.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    2024-01-29T23:01:54.85+00:00

    in clean design validation is required at every layer. but building a validation library that can be shared between layers is hard. ideally each layer would have its own.

    if you use fluent, then there should be a fluent library for each layer. If attached to the entities, then you are moving the UI validation definitions to the core entity. the downside is duplicating validation rules.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.