Boilerplate of API in .NET 8
Boilerplate of API in .NET Core 3.1
.NET 8
GitHub | Codecov |
---|---|
Boilerplate is a piece of code that helps you to quickly kick-off a project or start writing your source code. It is kind of a template - instead of starting an empty project and adding the same snippets each time, you can use the boilerplate that already contains such code.
Intention - The intention behind this project is to mix a variety of different approaches to show different available paths. That's why you can find here the Service approach mixed-up with Repository approach, or old-fashioned controllers mixed-up with brand new minimal API in a separate module (modular approach). As well as, it's a kind of playground for exploring frameworks, packages, tooling. At the end, You are in charge, so it's your decision to which path you would like to follow.
mysql:8
with DB initializationmcr.microsoft.com/mssql/server:2017-latest
with DB initializationnetcore-boilerplate:local
HappyCode.NetCoreBoilerplate.Api
ApiKey
Authorization filter - ApiKeyAuthorizationFilter.cs
ModelState
- ValidateModelStateFilter.cs
Serilog
configuration place - SerilogConfigurator.cs
Swagger
registration place - SwaggerRegistration.cs
HappyCode.NetCoreBoilerplate.Core
HappyCode.NetCoreBoilerplate.Db
.sql
and .cs
- S001_AddCarTypesTable.sql, S002_ModifySomeRows.cs
HappyCode.NetCoreBoilerplate.Api.IntegrationTests
HappyCode.NetCoreBoilerplate.Api.UnitTests
ApiKeyAuthorizationFilter.cs
- ApiKeyAuthorizationFilterTests.cs
HappyCode.NetCoreBoilerplate.Core.UnitTests
DbSet
faster - EnumerableExtensions.cs
HappyCode.NetCoreBoilerplate.ArchitecturalTests
Totally separate module, developed with a modular monolith approach.
The code organized around features (vertical slices).
HappyCode.NetCoreBoilerplate.BooksModule
HappyCode.NetCoreBoilerplate.BooksModule.IntegrationTests
Generally it is totally up to you! But in case you do not have any plan, You can follow below simple steps:
Just execute dotnet build
in the root directory, it takes HappyCode.NetCoreBoilerplate.sln
and build everything.
When running on
Linux
(i.e. WSL), make sure that all docker files (dockerfile, docker-compose and all mssql files) have line endingsLF
.
Just run docker-compose up
command in the root directory. After successful build and start of all services visit http://localhost:5000/swagger/.
To check that API has connection to both MySQL and MsSQL databases visit http://localhost:5000/health/.
When the entire environment is up and running, you can additionally run a migration tool to add some new schema objects into MsSQL DB.
To do that, go to src/HappyCode.NetCoreBoilerplate.Db
directory and execute dotnet run
command.
Run dotnet test
command in the root directory, it will look for test projects in HappyCode.NetCoreBoilerplate.sln
and run them.
If:
then please give me a star
, appreciate my work. Thanks!