src/BuildingBlocks/ and are designed for reusability, consistency, and maintainability.
Overview
The BuildingBlocks directory contains six main packages:Common
Authentication, endpoints, middleware, and shared utilities
MasarEagle.Constants
Shared constants for Aspire components and observability
MasarEagle.Database
Database connection and registration utilities
MasarEagle.Migrations
FluentMigrator base classes and migration service
NotificationContracts
Notification message contracts for cross-service messaging
SyncContracts
Synchronization message contracts for data consistency
Common
TheCommon building block provides essential shared functionality used across all services.
Authentication
Centralized JWT authentication and authorization configuration. Location:src/BuildingBlocks/Common/Authentication/
Endpoints
Interface-based endpoint registration system using static abstract interface members (C# 11+). Location:src/BuildingBlocks/Common/Endpoints/
Middleware
Global exception handling middleware with structured logging and metrics. Location:src/BuildingBlocks/Common/Middleware/GlobalExceptionMiddleware.cs
Key Features:
- Structured error logging with context
- OpenTelemetry metrics (error counters, duration histograms)
- RFC 7807 Problem Details responses
- Environment-specific error details
- Custom exception type handling
Wolverine Extensions
Wolverine messaging configuration with RabbitMQ and PostgreSQL transactional outbox support. Location:src/BuildingBlocks/Common/WolverineExtensions.cs
Constants
Shared constants for Aspire components and observability configuration. Location:src/BuildingBlocks/MasarEagle.Constants/
Aspire Components
Components.cs
Services
Services.cs
Database
Database connection management using Npgsql and LINQ to DB. Location:src/BuildingBlocks/MasarEagle.Database/
AppDataConnection
Base data connection class for LINQ to DB.AppDataConnection.cs
Database Registration
DatabaseRegistration.cs
Migrations
FluentMigrator base classes and automated migration service. Location:src/BuildingBlocks/MasarEagle.Migrations/
See: Database Migrations for detailed documentation.
Key Components
BaseMigration
Abstract base class with helper methods for creating tables, indexes, and foreign keys
DatabaseMigrationService
Background service that waits for database availability and runs migrations on startup
MigrationExtensions
Extension methods for registering migrations in the DI container
Notification Contracts
Message contracts for publishing notifications across services using Wolverine. Location:src/BuildingBlocks/MasarEagle.NotificationContracts/
Examples:
BookingCreatedNotificationBookingAcceptedNotificationTripCancelledNotificationBankTransferPendingReviewNotification
Sync Contracts
Message contracts for synchronizing data between services. Location:src/BuildingBlocks/MasarEagle.SyncContracts/
Examples:
UploadFileCommandUpdateDriverRatingCommandUpdatePassengerRatingCommand
Project References
To use a building block in your service:Best Practices
Keep Building Blocks Service-Agnostic
Keep Building Blocks Service-Agnostic
Building blocks should contain only generic, reusable code. Service-specific logic belongs in the service itself.
Version Carefully
Version Carefully
Changes to building blocks affect all services. Use semantic versioning and test thoroughly across all consuming services.
Document Public APIs
Document Public APIs
All public classes, methods, and extension methods should have XML documentation comments.
Use Dependency Injection
Use Dependency Injection
Provide extension methods for IServiceCollection to register services consistently.
Next Steps
Adding Features
Learn how to implement new features using these building blocks
Database Migrations
Understand the migration system and how to create schema changes