Boilerplate of API in .NET Core 3.1
Boilerplate of API in
.NET Core 3.1
| 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.
mysql:8with DB initialization
mcr.microsoft.com/mssql/server:2017-latestwith DB initialization
netcore-boilerplate:local
HappyCode.NetCoreBoilerplate.Api
ApiKeyAuthorization filter - ApiKeyAuthorizationFilter.cs
ModelState- ValidateModelStateFilter.cs
Serilogconfiguration place - SerilogConfigurator.cs
Swaggerconfiguration place - SwaggerConfigurator.cs
HappyCode.NetCoreBoilerplate.Core
HappyCode.NetCoreBoilerplate.Db
.sqland
.cs- S001_AddCarTypesTable.sql, S002_ModifySomeRows.cs
HappyCode.NetCoreBoilerplate.Api.IntegrationTests
HappyCode.NetCoreBoilerplate.Api.UnitTests
ApiKeyAuthorizationFilter.cs- ApiKeyAuthorizationFilterTests.cs
HappyCode.NetCoreBoilerplate.Core.UnitTests
DbSetfaster - EnumerableExtensions.cs
Keep in mind that entire environment has to be up and running.
HappyCode.NetCoreBoilerplate.Api.LoadTests
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 buildin the root directory, it takes
HappyCode.NetCoreBoilerplate.slnand build everything.
At first, you need to have up and running MySQL and MsSQL database servers on localhost with initialized database by mysql script and mssql script.
Then the application (API) can be started by
dotnet runcommand executed in the
src/HappyCode.NetCoreBoilerplate.Apidirectory. By default it will be available under http://localhost:5000/, but keep in mind that documentation is available under http://localhost:5000/swagger/.
Just run
docker-compose upcommand in the root directory and after successful start of 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.Dbdirectory and execute
dotnet runcommand.
Run
dotnet testcommand in the root directory, it will look for test projects in
HappyCode.NetCoreBoilerplate.slnand run them.
Need to migrate from
.NET Core 2.2to
.NET Core 3.1? There's an Microsoft article about this, but you can also, just in case, take a look at my migration commit where you can find the complete list of required changes.
If:
then please give me a
star, appreciate my work. Thanks!