How daohainam/microservice-patterns works
Project type and purpose
• This is an open‑source .NET solution (“MicroservicePatterns”) that provides:
• Core libraries (EventBus, DatabaseMigrationHelpers, ServiceDefaults, Shared, AppHost)
• Sample microservice implementations demonstrating key patterns (CQRS, Event Sourcing, Idempotent Consumer, Saga, Transactional Outbox, WebHook)
• Integration tests and unit tests validating these patterns
• It’s not a single deployable app but a framework + catalog of pattern‑based service templates.
File‑structure analysis
• Top‑level core libraries:
• EventBus (with a Kafka extension) – messaging abstractions and publisher/handler implementations
• MicroservicePatterns.AppHost – common Program.cs, DI/Configuration extensions for bootstrapping services
• MicroservicePatterns.DatabaseMigrationHelpers – EF Core migration helpers
• MicroservicePatterns.ServiceDefaults – default middleware/services
• MicroservicePatterns.Shared – cross‑cutting types (Consts, Pagination)
• patterns/ – a folder of subfolders, each a “pattern” containing one or more example services plus integration‑events projects and infra code:
• CQRS (Library services: Book, Borrower, Borrowing, BorrowingHistory + IntegrationEvents)
• EventSourcing (Banking.AccountService + IntegrationEvents + Infrastructure/EventStore)
• IdempotentConsumer (Catalog); Saga (multiple business domains: OnlineStore, TripPlanner)
• TransactionalOutbox (Abstractions, Aspire.Debezium, Banking.AccountService example, Infrastructure, IntegrationEvents, Publisher, Consumer)
• WebHook (DeliveryService + DispatchService, EventConsumer, Infrastructure)
• tests/ – integration tests orchestrating multiple patterns; unit tests for Saga.
Detail
• Microservice’s key components: API layer, Domain/Entity, Infrastructure (DB context, event handlers)
• Flow of integration events through EventBus or transactional outbox
• Pattern‑specific processors (e.g., Saga state machine, outbox poller, event store appenders)