How dpedwards/dotnet-core-micro-rabbit works
Project Type and Purpose
• This project implements a microservice architecture using .NET Core with a clear Domain Driven Design (DDD) approach.
• It spans multiple independent services, such as Banking and Transfer APIs, as well as a separate MVC web client.
• RabbitMQ is used as the centralized message bus to publish and subscribe for events and commands between services.
• The project is organized into several layers: Domain, Application, Data, API, and an MVC client.
Analyzing the File Structure
• Notice the distinct top-level project folders (e.g., MicroRabbit.Banking.Api, MicroRabbit.Transfer.Api, MicroRabbit.MVC) which represent separate services.
• There are dedicated projects for the Domain layers (e.g., MicroRabbit.Banking.Domain, MicroRabbit.Transfer.Domain) that include Models, Commands, Events, and Command/Event Handlers.
• The Application and Data layers in each bounded context (Banking and Transfer) reflect the separation of concerns (i.e., service interfaces and repositories).
• Infrastructure libraries such as MicroRabbit.Domain.Core, MicroRabbit.Infra.Bus, and MicroRabbit.Infra.IoC indicate the use of a central message bus and dependency injection for loose coupling.
Key Components
a. Banking Microservice:
• Banking API: Represented by MicroRabbit.Banking.Api (exposes endpoints via controllers), using a Startup configuration for dependency injection and middleware.
• Banking Application Layer: Contains the service (e.g., AccountService) and interfaces in MicroRabbit.Banking.Application.
• Banking Domain Layer: Contains domain models, commands (e.g., TransferCommand or CreateTransferCommand), and command handlers.
• Banking Data Layer: Represents the context (BankingDbContext) and repository (AccountRepository) interacting with SQL Server.
b. Transfer Microservice:
• Transfer API: MicroRabbit.Transfer.Api with its controllers and configurations.
• Transfer Application Layer: Contains business logic and service interfaces (ITransferService and TransferService).
• Transfer Domain Layer: Contains events (e.g., TransferCreatedEvent) and event handlers (e.g., TransferEventHandler), along with the repository interface.
• Transfer Data Layer: Contains the TransferDbContext and repository implementation (TransferRepository).
c. RabbitMQ Bus/Infrastructure:
• A central bus component (RabbitMQBus in MicroRabbit.Infra.Bus) handles event publishing and messaging between microservices.
• Domain Core components (Command, Event and the corresponding interfaces) that standardize commands and events.
d. MicroRabbit.MVC Client:
• The MVC project provides a user interface and interacts with the back-end services. It has its own controller (e.g., HomeController) and service (TransferService) for consuming API data.
• This client is meant to showcase the integration of UI with the microservices by interfacing with Banking and Transfer APIs.
Relationships and Interactions
• RabbitMQBus as a mediator between the Banking and Transfer services: for example, from Banking’s CommandHandlers and Event publishers to Transfer’s EventHandlers.
• Then, demonstrate consumer connectivity from the MVC client to the Banking API (and indirectly to the Transfer API if applicable) via REST calls/API calls.
• Usage of Swagger as an API documentation tool for the Banking and Transfer APIs.
Architectural Patterns and Design Principles
• Domain Driven Design (DDD): Separate domain, data, and application concerns in distinct projects.
• Microservices: Each API (Banking and Transfer) is an independent service with its own database and responsibility.
• Messaging via RabbitMQ: Use of publish/subscribe patterns to decouple communication between services.
• Dependency Injection: Noted in the MicroRabbit.Infra.IoC project for managing dependencies across the solution.
• Layered Architecture: Each microservice follows a layered structure (API → Application → Domain → Data).