Boilerplate of API in
.NET Core 3.1
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.
Source code contains
- Central Package Management (CPM)
[Autofac](https://autofac.org/) (Removed in PR19)
- Swagger + Swashbuckle
- FeatureManagement (Feature Flags, Feature Toggles)
- EF Core
- Code quality
- Sink: Async
- DbUp as a db migration tool
- Continuous integration
- The entry point of the app - Program.cs
- Simple Startup class - Startup.cs
- DbContext (with MySQL)
- DbContext (with MsSQL)
- Swagger and SwaggerUI (Swashbuckle)
- HostedService and HttpClient
- Simple exemplary API controllers - EmployeesController.cs, CarsController.cs
- Example of BackgroundService - PingWebsiteBackgroundService.cs
- Dto models
- DB models
- AppSettings models - Settings
- Core registrations - CoreRegistrations.cs
- Exemplary MySQL repository - EmployeeRepository.cs
- Exemplary MsSQL service - CarService.cs
- Console application as a simple db migration tool - Program.cs
- Sample migration scripts, both
.cs- S001_AddCarTypesTable.sql, S002_ModifySomeRows.cs
- Exemplary tests - EmployeesTests.cs, CarsTests.cs
- Exemplary tests - EmployeesControllerTests.cs
- Unit tests of
- Extension methods to mock
DbSetfaster - EnumerableExtensions.cs
- Exemplary tests - EmployeeRepositoryTests.cs, CarServiceTests.cs
Totally separate module, developed with a modular monolith approach.
The code organized around features (vertical slices).
- Sqlite db initializer - DbInitializer.cs
- Module configuration place - BooksModuleConfigurations.cs
- Exemplary tests - BooksTests.cs
How to adapt to your project
Generally it is totally up to you! But in case you do not have any plan, You can follow below simple steps:
- Download/clone/fork repository
- Remove components and/or classes that you do not need to 🔥
- Rename files (e.g. sln, csproj, ruleset), folders, namespaces etc 📝
- Appreciate the work ⭐
Build the solution
dotnet build in the root directory, it takes
HappyCode.NetCoreBoilerplate.sln and build everything.
Start the application
Then the application (API) can be started by
dotnet run command executed in the
By default it will be available under http://localhost:5000/, but keep in mind that documentation is available under
docker-compose up command 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.Db directory and execute
dotnet run command.
Run unit tests
dotnet test command in the root directory, it will look for test projects in
HappyCode.NetCoreBoilerplate.sln and run them.
- any idea? Please create an issue.
Be like a star, give me a star! ⭐
- you like this repo/code,
- you learn something,
- you are using it in your project/application,
then please give me a
star, appreciate my work. Thanks!