Introduction
This is Microservice Boilerplate repository. The Boilerplate is aimed to unify behavior among microservice implementations and avoid developer to duplicate infrastructural code. The repository contains 3 solutions:
-
Boilerplate - contains basic Nuget libraries that are supposed to be published and re-used by all microservice instances that follows the Boilerplate;
-
Boilerplate.BlaBlaBla - a typical microservice solution with synchronous and asynchronous contracts, relational database, integration tests;
-
RestApi.Template - a Nuget library that allows to publish typical microservice solution as reusable dotnet template.
Technologies
- ASP.NET Core 8
- Entity Framework Core 8
- MediatR
- OpenApi + NSwag
- FluentValidation
- FluentAssertions
- xUnit
- Moq
- Respawn
- MassTransit
RestApi Template Solution Overview
Current solution follows Onion Architecture. More information about layers can be found below. With .NET core it’s now possible to create custom templates for any type of projects. Please read more on how to customize the template before starting.
Getting Started
Using dotnet new command
Suggested way to start development on new API is by using dotnet template:
- Install Azure Artifacts Credential Provider from the official page
-
Install the template:
dotnet new -i RestApi.Template --interactive --nuget-source https://pkgs.dev.azure.com/if-it/_packaging/Boilerplate/nuget/v3/index.json
Same command can be used if template is already installed and needs to be updated to latest version.
-
Create api from template:
dotnet new rest-api -n [name of the project]
In Debug mode migrations are automatically launched during startup. So the only thing that developer needs to do in order to launch web api is press F5.
Presentation Layer (WebApi)
This layer is based on ASP.NET Core framework. Presentation layer-specific middlewares (MediatR, ProblemDetails) are configured via Boilerplate.Mvc. Persistence layer-specific Mvc filters are configured additionally via Boilerplate.Mvc.EntityFramework. Orchestration feature is supported by Boilerplate.Orchestration.
Application Layer
Contains all application logic. The layer wires up Domain & Persistence layers. Application logic is triggered through in-process messaging and MediatR.
Domain Layer
Contains DDD/Ef entities, DDD value objects, enumerators, exceptions, interfaces, types and logic specific to the business of the product.
Rich Domain model should be implemented with the following concepts in mind:
- Validation through Specification pattern
- Aggregate Root or Root Entity Patten
- Value Objects
Persistence Layer
Contains description and configuration of EF Core DbContext through fluent validation. Uses domain model as a source for data model. Is based on the nuget Boilerplate.EntityFramework.
Typical Package Dependencies in Microservice
Описание
Пет-проект с реализацией проекта-шаблона для микросервиса с поддержкой синхронного и асинхронного взаимодействия, базы данных, интеграционных тестов, DDD.