Update!
Boilerplate become .NET 6!
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.
Here you can find such boilerplate of API that I build in .NET Core 3.1
.NET 6
.
Source code contains
-
[Autofac](https://autofac.org/) (Removed in PR19) - Swagger + Swashbuckle
- FeatureManagement (Feature Flags, Feature Toggles)
- HealthChecks
- EF Core
- Tests
- Integration tests with InMemory database
- FluentAssertions
- xUnit
- TestServer
- Unit tests
- Load tests
- Integration tests with InMemory database
- Code quality
- Docker
- Dockerfile
-
Docker-compose
-
mysql:8
with DB initialization -
mcr.microsoft.com/mssql/server:2017-latest
with DB initialization netcore-boilerplate:local
-
-
Serilog
- Sink: Async
- Enrich: CorrelationId
- DbUp as a db migration tool
- Continuous integration
Architecture
Api
- Simple Startup class - [Startup.cs]
- MvcCore
- DbContext (with MySQL)
- DbContext (with MsSQL)
- Swagger and SwaggerUI (Swashbuckle)
- HostedService and HttpClient
- FeatureManagement
- HealthChecks
- MySQL
- MsSQL
- Filters
- Simple
ApiKey
Authorization filter - [ApiKeyAuthorizationFilter.cs] - Action filter to validate
ModelState
- [ValidateModelStateFilter.cs] - Global exception filter - [HttpGlobalExceptionFilter.cs]
- Simple
- Configurations
- Dependency registration place - [ContainerConfigurator.cs]
-
Serilog
configuration place - [SerilogConfigurator.cs] -
Swagger
configuration place - [SwaggerConfigurator.cs]
- Simple exemplary API controllers - [EmployeesController.cs], [CarsController.cs]
- Example of BackgroundService - [PingWebsiteBackgroundService.cs]
Core
- Dto models
- DB models
- Registration module - [GeneralRegisterModule.cs]
- Exemplary MySQL repository - [EmployeeRepository.cs]
- Exemplary MsSQL service - [CarService.cs]
- AppSettings models
- Simple MySQL DbContext - [EmployeesContext.cs]
- Simple MsSQL DbContext - [CarsContext.cs]
DB Migrations
- Console application as a simple db migration tool - [Program.cs]
- Sample migration scripts, both
.sql
and.cs
- [S001_AddCarTypesTable.sql], [S002_ModifySomeRows.cs]
Tests
Integration tests
- Infrastructure
- Fixture with TestServer - [TestServerClientFixture.cs]
- TestStartup with InMemory databases - [TestStartup.cs]
- Simple data feeders - [EmployeeContextDataFeeder.cs], [CarsContextDataFeeder.cs]
- Exemplary tests - [EmployeesTests.cs], [CarsTests.cs]
Unit tests
Controller tests - [EmployeesControllerTests.cs]
Extension methods to mock
DbSet
faster - [EnumerableExtensions.cs]Exemplary tests - [EmployeeRepositoryTests.cs], [CarServiceTests.cs]
Load tests
Keep in mind that entire environment has to be up and running.
- Base class for controller - [LoadTestsBase.cs]
- Exemplary tests - [EmployeesControllerTests.cs], [CarsControllerTests.cs]
Source code
The full source code with detailed information you can find on my GitHub: https://github.com/lkurzyniec/netcore-boilerplate
Top comments (1)
nice! just what newbie like us needed