The .NET 5 SDK is a kind of milestone in the .NET world. The .NET 5 include the .NET Core SDK characters and the .NET 4.8 SDK characters, which are the MVC pattern. These have slight differences, but it is still a good choice from the enterprise viewpoint because the .NET 5 SDK is a stabilizing product.
The onion architecture can use any computer language in web frameworks because the onion architecture is a kind of principle or concept based on the original MVC pattern concept theory. Many architecture concepts are from the MVC pattern theory, so when considering the web application architecture option, the developers should go back to basics to choose the basic architecture – onion architecture which is sometimes a good choice in any situation. It doesn’t mean the onion architecture can use anyone’s cases. Advanced architecture is a good choice that needs to be according to the situation conditions. e.g., Hexagonal architecture.

How to implement the .NET 5 web application with Onion architecture?

The first step that creates the website project based on the .NET 5 SDK without the HTTPS and docker setting files.
Note: This sample setting is for let the sample is easy to understand. If you want to your project enable the https and the creating docker file, you can check these items.
Second, according to the onion architecture concepts, create the infra and core projects. The web application project architecture will have the shared kernel projects when the web project is a huge project size. Many massive project case requests want the team’s developer to only focus on the business service of the core projects because the system design professor doesn’t want the programmers to modify the shared kernel projects and the infra projects.
Finally, the project’s object-relational mapping(ORM) uses the EF Core 5 with a Microsoft SQL server. EF Core isn’t only an ORM option, other ORM options have the EF, the dapper, and the ASP.DOT.

How to implement the .NET 5 web API application with Onion architecture?
According to the onion architecture description, the core and the infra projects are the same projects, so the core and infra projects don’t need to create and write again. These projects only reference the API projects that will be can work. If the core and infra projects don’t include the dependence inversion design concepts, the API project needs the medium layer projects to do the adapter effect. The dependence inversion design pattern implemented is crucial in the mini API of the modern because it affects every request to implement the class lifecycle. If the web project doesn’t want to implement it, the .NET 5 API application performance would not be good; which design pattern goes back to the basics of the traditional .NET design concepts. I prefer that the reader use the standard library to implement the core and infra layers because the standard library can be more compatible with the .Net framework version.

Step 1. Create the web application without the HTTPS and the docker files.
Step 2. Create the class standard library and target the standard 2.0 version. (Infra and Core projects)
Note: If the developers want the web/API, the core and infra project .Net version are the as same version, the core, and infra project can use .NET 5 framework, but the developers must be careful it choose because it is not the minimal and standard library, which would not be well compatible with other .Net framework versions.
Step 3. Write the CRUD in the Infra projects and the database connection source code part. This part will focus on implementing the database connection instance and basic-level CRUD by the generic type mechanism.
Step 4. Write the basic CRUD of the business application in the Core projects. This part focus on implementing the infra project’s basic-level CRUD with the data transfer objects(DTO) and the entity table model class object exchange.
Step 5. Register the Core/Infra project’s services part and the database connection string in the API/Web projects.
Step 6. Write the executing CRUD gateway source code in the API/Web projects which mean executes the CRUD service of the Core project.
If you want to read more information please refer to this blog – Microservices – Onion architecture
Reference
- Microservices – Onion architecture
- Building MVC pattern project by Visual Studio 2017 ( ASP.Net framework Part )
- Building MVC pattern project by Visual Studio 2017 ( ASP.Net Core Part )
- UnitOfWork pattern concepts in .NET
- Microservices – DDD
1 Comment