Boilerplate of API in .NET 8
GitHub | Codecov | Docker Hub |
---|---|---|
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:2022-latest
with DB initializationnetcore-boilerplate:compose
To run the solution, use one of the options:
After successful start of the solution in any of above option, check useful endpoints:
When running standalone, features like
cars
andemployees
might be disabled.
Execute dotnet run --project src/HappyCode.NetCoreBoilerplate.Api
in the root directory.
When running in docker, features like
cars
andemployees
are disabled.
Simply execute docker run --rm -p 5000:8080 --name netcore-boilerplate lkurzyniec/netcore-boilerplate
to download and spin up a container.
To run in docker with your own image, execute docker build . -t netcore-boilerplate:local
in the root directory to build an image,
and then docker run --rm -p 5000:8080 --name netcore-boilerplate netcore-boilerplate:local
to spin up a container with it.
When running on
Linux
(i.e. WSL), make sure that all docker files (dockerfile, docker-compose and all mssql files) have line endingsLF
.
Just execute docker-compose up
command in the root directory.
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.
Generally it is totally up to you! But in case you do not have any plan, You can follow below simple steps:
sln
or csproj
), folders, namespaces etc :memo:HappyCode.NetCoreBoilerplate.Api
ApiKey
Authorization filter - ApiKeyAuthorizationFilter.csModelState
- ValidateModelStateFilter.csSerilog
configuration place - SerilogConfigurator.csSwagger
registration place - SwaggerRegistration.csHappyCode.NetCoreBoilerplate.Core
HappyCode.NetCoreBoilerplate.Db
.sql
and .cs
- S001_AddCarTypesTable.sql, S002_ModifySomeRows.csHappyCode.NetCoreBoilerplate.Api.IntegrationTests
HappyCode.NetCoreBoilerplate.Api.UnitTests
HappyCode.NetCoreBoilerplate.Core.UnitTests
DbSet
faster - EnumerableExtensions.csHappyCode.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
If:
then please give me a star
, appreciate my work. Thanks!
You are also very welcome to acknowledge my time by buying me a small coffee.