ProductionReady.Microservice.Template 1.0.1

dotnet new install ProductionReady.Microservice.Template::1.0.1
                    
This package contains a .NET Template Package you can call from the shell/command line.

Production-Ready .NET 8 Microservice Template

A comprehensive, production-ready .NET 8 microservice template that follows Clean Architecture principles and implements CQRS pattern with enterprise-grade features.

๐Ÿš€ Quick Start

Install the Template

# Install from NuGet (once published)
dotnet new install ProductionReady.Microservice.Template

# Or install from local package
dotnet new install ProductionReady.Microservice.Template.1.0.0.nupkg

Create a New Microservice

# Basic usage
dotnet new microservice -n UserManagement -CompanyName Acme

# With custom options
dotnet new microservice -n OrderProcessing -CompanyName Acme -Port 5100 -HttpsPort 5101 --EnableDocker true --EnableKubernetes true

Available Parameters

Parameter Type Default Description
CompanyName string "Company" Your company or organization name
ServiceName string "ServiceName" The name of your microservice
Port integer 5000 HTTP port for the service
HttpsPort integer 5001 HTTPS port for the service
IncludeDatabase bool true Include Entity Framework and database configuration
DatabaseProvider choice SqlServer Database provider (SqlServer/PostgreSQL)
EnableDocker bool true Include Docker support
EnableKubernetes bool true Include Kubernetes manifests
EnableGitHubActions bool true Include GitHub Actions CI/CD pipeline

๐Ÿ—๏ธ Architecture

The template follows Clean Architecture with these layers:

โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ {Company}.{ServiceName}.Domain/           # Domain entities and business rules
โ”‚   โ”œโ”€โ”€ {Company}.{ServiceName}.Application/      # Business logic and CQRS handlers
โ”‚   โ”œโ”€โ”€ {Company}.{ServiceName}.Infrastructure/   # Data access and external services
โ”‚   โ””โ”€โ”€ {Company}.{ServiceName}.Api/             # REST API controllers and configuration
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ {Company}.{ServiceName}.Application.Tests/ # Unit tests
โ”‚   โ””โ”€โ”€ {Company}.{ServiceName}.Api.Tests/        # Integration tests
โ”œโ”€โ”€ docker/                                      # Docker configuration
โ”œโ”€โ”€ k8s/                                         # Kubernetes manifests
โ””โ”€โ”€ .github/workflows/                           # CI/CD pipeline

โœจ Features Included

๐Ÿ›๏ธ Architecture & Patterns

  • Clean Architecture with proper dependency inversion
  • CQRS pattern with MediatR
  • Domain-Driven Design principles
  • Repository pattern with Entity Framework Core
  • Decorator pattern for cross-cutting concerns

๐Ÿ”ง Technical Features

  • .NET 8 with latest features
  • Entity Framework Core 8 for data access
  • MediatR for CQRS implementation
  • FluentValidation for input validation
  • AutoMapper for object mapping
  • Serilog for structured logging

๐Ÿ›ก๏ธ Security & Reliability

  • Global exception handling middleware
  • Request/Response logging middleware
  • Security headers configuration
  • CORS configuration
  • Health checks with multiple endpoints
  • Input validation with custom error responses

๐Ÿณ DevOps & Deployment

  • Docker support with multi-stage builds
  • Docker Compose for local development
  • Kubernetes manifests for production deployment
  • GitHub Actions CI/CD pipeline
  • Health checks for container orchestration

๐Ÿงช Testing

  • Unit tests with xUnit
  • Integration tests with TestHost
  • Test utilities and fixtures
  • Code coverage configuration

๐Ÿš€ Getting Started with Generated Project

After creating your microservice:

1. Build and Run Locally

cd YourServiceName
dotnet build
dotnet run --project src/YourCompany.YourServiceName.Api

2. Run with Docker

docker build -t yourservice .
docker run -p 5000:5000 yourservice

3. Run with Docker Compose

docker-compose up

4. Deploy to Kubernetes

kubectl apply -f k8s/

๐Ÿ“Š API Endpoints

The generated microservice includes:

  • GET /health - Health check endpoint
  • GET /health/ready - Readiness probe
  • GET /health/live - Liveness probe
  • GET /swagger - API documentation
  • GET /api/weatherforecast - Sample endpoint

๐Ÿ”ง Configuration

appsettings.json

{
  "Serilog": {
    "MinimumLevel": "Information"
  },
  "AllowedHosts": "*",
  "Cors": {
    "AllowedOrigins": ["http://localhost:3000"]
  }
}

Environment Variables

Variable Description Default
ASPNETCORE_ENVIRONMENT Environment (Development/Staging/Production) Development
ASPNETCORE_URLS URLs to listen on http://+:5000
ConnectionStrings__DefaultConnection Database connection string -

๐Ÿงช Testing

# Run all tests
dotnet test

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

# Run specific test project
dotnet test tests/YourCompany.YourServiceName.Application.Tests

๐Ÿ“š Documentation

The generated project includes:

  • README.md - Project overview and setup instructions
  • API documentation - Swagger/OpenAPI specs
  • Architecture decision records - In the docs/ folder
  • Deployment guides - Docker and Kubernetes instructions

๐Ÿค Contributing

  1. Fork the template repository
  2. Create a feature branch
  3. Make your changes
  4. Test the template generation
  5. Submit a pull request

๐Ÿ“„ License

This template is licensed under the MIT License. See the LICENSE file for details.

๐Ÿท๏ธ Template Management

Uninstall Template

dotnet new uninstall ProductionReady.Microservice.Template

List Installed Templates

dotnet new list

Template Help

dotnet new microservice --help

Happy coding! ๐ŸŽ‰

Create robust, scalable microservices with this production-ready template that follows industry best practices and includes everything you need to get started quickly.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 471 7/21/2025

v1.0.1 - Production-Ready Microservice Template
     
     🚀 Features:
     โ€ข Clean Architecture with Domain, Application, Infrastructure, and API layers
     โ€ข CQRS pattern implementation with MediatR
     โ€ข Structured logging with Serilog and multiple enrichers
     โ€ข Global exception handling and request logging middleware
     โ€ข FluentValidation for robust input validation
     โ€ข Health checks with readiness/liveness probes
     โ€ข Docker support with optimized multi-stage builds
     โ€ข Kubernetes deployment manifests for production
     โ€ข GitHub Actions CI/CD pipeline with testing and security scans
     โ€ข Security headers and CORS configuration
     โ€ข Comprehensive unit and integration tests
     โ€ข AutoMapper for object mapping
     โ€ข Entity Framework Core with repository pattern
     โ€ข Caching strategies with decorators
     โ€ข Complete documentation and setup guides
     
     🛡๏ธ Security:
     โ€ข No vulnerable packages (all dependencies verified)
     โ€ข Security best practices implemented
     โ€ข HTTPS enforcement and security headers
     
     📦 Template Options:
     โ€ข Configurable company and service names
     โ€ข Optional Docker and Kubernetes support
     โ€ข Database provider selection (SQL Server/PostgreSQL)
     โ€ข GitHub Actions CI/CD pipeline inclusion
     โ€ข Customizable ports and configuration