A modern, scalable .NET template featuring Domain-Driven Design (DDD), Event Sourcing, CQRS patterns, and .NET Aspire orchestration.
- Domain-Driven Design (DDD): Well-structured domain models with aggregates and value objects
- Event Sourcing: Full audit trail with event-based aggregate persistence
- CQRS: Separated read and write models
- Event Bus: In-memory event publishing and subscription
- Entity Framework Core: PostgreSQL with EF Core migrations
- .NET Aspire: Container orchestration with Redis and PostgreSQL
- OpenAPI: Built-in API documentation with Scalar
- Serilog: Structured logging
- Vue.js: Modern frontend with Vite
- .NET 10: Latest C# features and performance improvements
- .NET 10 SDK
- Docker & Docker Compose (for Aspire)
- PowerShell
git clone https://github.com/pmdevers/dotnet-project-template.git
cd dotnet-project-templateThe easiest way to run the entire stack:
dotnet run --project src/AppHost/Template.AppHost.csprojThis starts:
- PostgreSQL database
- Redis cache
- ASP.NET Core API
- Vue.js frontend
- API: http://localhost:5000
- API Docs: http://localhost:5000/scalar
- Frontend: http://localhost:5173
src/
βββ AppHost/ # .NET Aspire orchestration
βββ Api/ # ASP.NET Core API
β βββ Domain/ # Business logic (entities, aggregates, value objects)
β βββ Infrastructure/ # Data access, events, repositories
β βββ Features/ # API endpoints and command handlers
β βββ Configuration/ # Service and middleware setup
βββ WebUi/ # Vue.js frontend
βββ ServiceDefaults/ # Shared configuration
βββ Generators/ # Source generators
- Aggregates:
Car,Reservation - Value Objects:
LicensePlate - Events:
CarRegistered,ReservationCreated, etc.
- Data:
AppDbContextwith EF Core for PostgreSQL - Events: Event sourcing tables and queries
- EventBus: Async event publishing and subscription
- Migrations: Database schema versioning
- Cars: Register and query vehicles
- Reservations: Create and retrieve reservations (event-sourced)
Two migrations are included:
- InitialCreate: Creates
Carstable - EventSourcedAggregate: Creates
Eventstable for event sourcing
Apply migrations automatically on startup via AppDbContextMigrationService.
Via .NET Aspire:
var postgres = builder.AddPostgres("appdb");Automatically injected as ConnectionStrings:appdb
Manual setup:
"ConnectionStrings": {
"appdb": "Host=localhost;Database=streamsharp;Username=postgres;Password=postgres"
}// Create a reservation (event-sourced aggregate)
var reservation = Reservation.Create(customerId, carId, startDate, endDate);
var repo = serviceProvider.GetRequiredService<IRepository<Reservation, ReservationId>>();
repo.Add(reservation);
await unitOfWork.SaveChangesAsync();
// Load from history
var loaded = await repo.TryFindAsync(reservation.Id);// Command: create via endpoint
app.MapPost("/reservations", CreateReservation.Handle);
// Query: read via ICarQueries or EventQueries
var cars = await carQueries.GetAllAsync();
var reservation = await dbContext.GetAggregate<Reservation>(id);// Subscribe to events
services.AddEventBus();
// Publish automatically on domain events
await unitOfWork.SaveChangesAsync(); // Triggers event dispatch- Create entity in
Domain/Entities - Create configuration in
Infrastructure/Data/Config - Add
DbSet<T>toAppDbContext - Create migration:
dotnet ef migrations add YourMigrationName
- Create feature in
Features/ - Implement handler with dependency injection
- Register in
ApiEndpoints.cs
// In EventBusExtensions.cs
bus.Subscribe<CarRegistered>(async @event =>
{
logger.LogInformation("Car registered: {@Event}", @event);
});Core dependencies:
Microsoft.EntityFrameworkCore(10.0.0)Npgsql.EntityFrameworkCore.PostgreSQLMicrosoft.AspNetCore.OpenApiSerilog& related sinks
# Run all tests
dotnet test
# Run specific test project
dotnet test src/Api/Template.Api.csprojAfter running the app, visit:
- Scalar UI: http://localhost:5000/scalar
- OpenAPI JSON: http://localhost:5000/openapi/v1.json
- Ensure PostgreSQL is running (via Aspire or Docker)
- Check
POSTGRES_CONNECTION_STRINGenvironment variable
- Delete
AppDbContextMigrationServiceoutput and retry - Verify EF Core tools:
dotnet ef --version
- Update .NET:
dotnet --versionshould be 10.0.0+ - Reinstall:
dotnet tool update -g dotnet-aspire-latest
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Commit changes
- Push and open a pull request
This project is open source and available under the MIT License.
Created by: @pmdevers
Repository: https://github.com/pmdevers/dotnet-project-template