https://github.com/agutak/aspnet-onion-template
ASP.NET Onion Architecture Solution Template
https://github.com/agutak/aspnet-onion-template
asp-net csharp dotnet dotnet6 dotnet7 dotnet8 entity-framework-core mongodb mssql net8 onion-architecture template
Last synced: 6 months ago
JSON representation
ASP.NET Onion Architecture Solution Template
- Host: GitHub
- URL: https://github.com/agutak/aspnet-onion-template
- Owner: agutak
- License: mit
- Created: 2022-07-16T14:24:07.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-28T18:18:57.000Z (about 2 years ago)
- Last Synced: 2025-11-06T21:15:38.335Z (8 months ago)
- Topics: asp-net, csharp, dotnet, dotnet6, dotnet7, dotnet8, entity-framework-core, mongodb, mssql, net8, onion-architecture, template
- Language: C#
- Homepage:
- Size: 274 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#  ASP.NET Onion Architecture Solution Template
[](https://github.com/agutak/aspnet-clean-template/actions/workflows/codeql-analysis.yml)
[](https://www.nuget.org/packages/AHutak.OnionArchitecture.AspNet)
[](https://www.nuget.org/packages/AHutak.OnionArchitecture.AspNet)
## Template Description
This is a template package with two solution templates:
- ASP.NET Web API application,
- gRPC application.
Both of these solutions are built according to the Onion Architecture.
You can create a new solution based on one of these templates by installing the associated NuGet package and using it from Visual Studio 2022 and later or directly with DotNet CLI commands.
Each template contains:
- Domain, Application, Persistence, Infrastructure, and API projects,
- MS SQL and MongoDB persistence layer implementations which the user can choose during solution creation,
- Optional Entity Framework migrations project,
- Unit tests and Component tests template projects,
The template of your choice contains either:
- API project with REST minimal APIs and, optionally, standard controllers
- API project with gRPC service
## Getting Started
### Building nuget package from source code
To build the NuGet package from the source code follow the next steps:
- [install nuget.exe](https://learn.microsoft.com/en-us/nuget/install-nuget-client-tools?tabs=windows#install-nugetexe)
- run nuget pack command from the root of the repository
``` nuget pack aspnet-onion-template.nuspec -NoDefaultExcludes ```
### Installing the templates
To install this package on your system from a NuGet package stored at nuget.org run the following command with the latest package version
``` dotnet new --install AHutak.OnionArchitecture.AspNet:: ```
To install this package on your system from a local nupkg file run the following command with the latest package version
``` dotnet new install /AHutak.OnionArchitecture.AspNet..nupkg ```
For more information see [Installing a template package.](https://learn.microsoft.com/en-us/dotnet/core/tools/custom-templates#install-a-template-package)
You should see the message shown below which indicates a successful installation

After that you have several options, to use it either from Visual Studio 2022 or from the command line.
#### From Visual Studio 2022:


#### From command-line:
``` dotnet new oa-sln-aspnet-grpc -n Your-Project-Name ```
or
``` dotnet new oa-sln-aspnet-webapi -n Your-Project-Name ```
To view other available command-line solution parameters please run
``` dotnet new oa-sln-aspnet-grpc --help ```
or
``` dotnet new oa-sln-aspnet-webapi --help ```
At the moment these templates support two persistence layer implementations:
- MS SQL with EF Core
- MongoDB.
You can select one of them during solution creation.
### Launching the solution
The next step to launch the newly created solution is updating the appsettings json files in the API project.
You will need to provide the database connection information.
Depending on the selected Persistence layer implementation appsettings json files will contain one of the configuration sections:
- for MongoDB
```
"MongoDbSettings": {
"ConnectionString": "",
"DatabaseName": ""
}
```
- for MS SQL
```
"ConnectionStrings": {
"MyDbConnectionString": ""
}
```
If MS SQL persistence implementation was selected during solution creation you have to run migrations on your database.
This step can be done with the following commands run from the root directory of your solution (assuming you have installed the "dotnet ef" tools)
```
dotnet ef database update -p src/your-solution-name.Persistence.MsSql.Migrations/ -s src/your-solution-name.Persistence.MsSql.Migrations/ --connection 'your-connection-string'
```
For more information on Entity Framework Core tools see [Entity Framework Core tools reference](https://docs.microsoft.com/en-us/ef/core/cli/dotnet)
After that, you can launch the API project from Visual Studio or the command line.
## Support
If you are having problems, please let us know by [raising a new issue](https://github.com/agutak/aspnet-onion-template/issues/new/choose).
## License
This project is licensed with the [MIT license](LICENSE).