question

ZaffarKhan-8136 avatar image
0 Votes"
ZaffarKhan-8136 asked TimonYang-MSFT edited

Implement Clean Architecture in Asp.Net Core Web App

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?

dotnet-csharpdotnet-aspnet-core-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered DuaneArnold-0443 edited

@ZaffarKhan-8136

Well you start off with understanding speration of concerns SoC.

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

https://docs.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://docs.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://docs.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://docs.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





.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.