Implement Clean Architecture in Asp.Net Core Web App

Zaffar Khan 1 Reputation point
2021-03-27T08:56:01.907+00:00

Greetings,

I was Asp.Net programmer and quite the programming field almost 2 years ago, now I have started back and found that the Clean Architecture is a good approach to structure project, so I have searched about it on google but all the resources I have found is confusing and things mixed up in my mind.
I am familiar with and use the N-Tire Architecture in my past experience but still, the Clean/Onion Architecture is mixed up in my mind.

I am looking for Suggestion/Helping Materials regarding:

The proper way to learn the Clean Architecture, and if there is another advanced and good approach then please mention it.
When and where to apply the Clean Architecture, as we already have the MVC and N-Tire but Why we have to apply the Clean Architecture?
It will be considered a best practice to apply Clean Architecture on small applications like a simple app consist of just CRUD or have the basic functionality but in future we have to create an API for it?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,080 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,099 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Duane Arnold 3,211 Reputation points
    2021-03-27T12:04:44.19+00:00

    @Zaffar Khan

    Well you start off with understanding speration of concerns SoC.

    https://en.wikipedia.org/wiki/Separation_of_concerns

    https://learn.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/architectural-principles

    https://www.c-sharpcorner.com/UploadFile/56fb14/understanding-separation-of-concern-and-Asp-Net-mvc/

    You should understand the models used in MVC.

    https://deviq.com/terms/kinds-of-models

    You should understand the viewmodel.

    https://www.dotnettricks.com/learn/mvc/understanding-viewmodel-in-aspnet-mvc

    https://learn.microsoft.com/en-us/archive/msdn-magazine/2016/may/asp-net-writing-clean-code-in-asp-net-core-with-dependency-injection

    Layered or N-Tier...

    https://learn.microsoft.com/en-us/previous-versions/msp-n-p/ee658117(v=pandp.10)

    DTO(s) travel between layers or tiers -- not the persistence model.

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    You should understand what is being discussed.

    https://learn.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/overview/understanding-models-views-and-controllers-cs

    <copied>

    An MVC model contains all of your application logic that is not contained in a view or a controller. The model should contain all of your application business logic, validation logic, and database access logic.

    A view should contain only logic related to generating the user interface. A controller should only contain the bare minimum of logic required to return the right view or redirect the user to another action (flow control). Everything else should be contained in the model.

    In general, you should strive for fat models and skinny controllers. Your controller methods should contain only a few lines of code. If a controller action gets too fat, then you should consider moving the logic out to a new class in the Models folder.

    <end>

    In the Models folder in the example solution out on Github, you see two types of classes suffixed with DM (Domain Model( and VM (ViewModel). And everything presented has been implemented in the solution.

    https://github.com/darnold924/PublishingCompany

    I am also using the DAO pattern in the DAL.

    https://javarevisited.blogspot.com/2013/01/data-access-object-dao-design-pattern-java-tutorial-example.html

    You should look into Razor Pages and Blazor both use the ASP.NET MVC pipeline.

    HTH

    .

    0 comments No comments