This is a learning project aimed at understanding the principles and implementation of Modular Monoliths in .NET 9.
- .NET 9
- Ardalis.GuardClauses: A library for guard clauses
- Ardalis.Result: A library for handling operation results
- Dapper: A simple ORM and EFCore alternative
- FastEndpoints: An alternative to minimal APIs
- MediatR: Simple mediator pattern implementation
- MimeKit: To Send Emails - Multipurpose Internet Mail Extension (MIME)
- Scalar: An alternative to Swagger
- Serilog: A diagnostic logging library
- xUnit: A testing framework
- FluentAssertions: A fluent assertion library
- ArchUnitNET: An architecture testing library
- MongoDB: A NoSQL database - Used in the Outbox Pattern
- MSSQL: A relational database- Used for the modules main databases
- During the development of this project, I used the local MSSQL instance (localdb) for database operations.
- Papercut: A Simple Desktop Email Server - Used for testing
- Redis: An in-memory data structure store - Used for the Materialized View Pattern
To create the Initial migration go to the Vini.ModularMonolith.Example.Web directory and this command:
dotnet ef migrations add Initial -c BooksDbContext -p ..\Vini.ModularMonolith.Example.Books\Vini.ModularMonolith.Example.Books.csproj -s .\Vini.ModularMonolith.Example.Web.csproj -o Data/MigrationsTo run the migrations
dotnet ef database update --context BooksDbContextTo run migrations for the appsettings.Testing.json file, run this command:
dotnet ef database update -c BooksDbContext -p Vini.ModularMonolith.Example.Web/Vini.ModularMonolith.Example.Web.csproj -- --environment TestingTo create the Initial migration go to the Vini.ModularMonolith.Example.Web directory and this command:
dotnet ef migrations add Initial -c UsersDbContext -p ..\Vini.ModularMonolith.Example.Users\Vini.ModularMonolith.Example.Users.csproj -s .\Vini.ModularMonolith.Example.Web.csproj -o Data/MigrationsTo run the migrations
dotnet ef database update --context UsersDbContextTo create the Initial migration go to the Vini.ModularMonolith.Example.Web directory and this command:
dotnet ef migrations add Initial -c OrderProcessingDbContext -p ..\Vini.ModularMonolith.Example.OrderProcessing\Vini.ModularMonolith.Example.OrderProcessing.csproj -s .\Vini.ModularMonolith.Example.Web.csproj -o Data/MigrationsTo run the migrations
dotnet ef database update --context OrderProcessingDbContextHas some architecture tests.
To run papercut as a container, run this command:
docker run --name modular-monolith-papercut -d -p 25:25 -p 37408:37408 jijiechen/papercut:latestTo run MongoDB as a container, run this command:
docker run --name modular-monolith-mongo -d -p 27017:27017 mongoThis module has an event ingestion system that saves the necessary report data in a dedicated database.
This module houses cross-cutting concerns and shared functionalities used by multiple modules within the system, like:
- MediatR Behaviors: These are pipeline behaviors that can encapsulate logic such as:
- Logging: Using tools like Serilog to log request handling, performance metrics, or errors in a centralized manner.
- Validation: Implementing validation logic using FluentValidation, ensuring requests are pre-validated before reaching their handlers.
- Domain Events: These are events that are raised within the domain and can be handled by other modules (or external systems).