Modular Monolith

eShop as a modular monolith: one database, no MediatR, no RabbitMQ

Habr C# (ru) gandjustas
Modular Monolith

Part two of the eShop modular monolith migration folds four DbContexts and four databases into one host context, deletes RabbitMQ and MediatR from the ordering flow, and documents the five bugs that distribution had been hiding.

Key points

  • Four DbContexts and four databases merged into one ShopContext, with a separate schema per module (catalog, ordering, identity, webhooks, eventlog).
  • Analyzer MOD0016 and C# 14 extension blocks move DbSet properties off the context, so module query code compiles untouched.
  • ApplyModuleConfigurations from FusionModules.EntityFrameworkCore builds the model from IEntityTypeConfiguration classes found in loaded module assemblies.
  • The order path dropped from 8 RabbitMQ events, 12 handlers and 4 transactions to two method calls and two transactions.
  • The ordering module keeps 38 of 114 files; author code falls from 10233 lines and 366 types to 7655 lines and 237 types.
  • Merging surfaced five bugs, including invalid orders returning 200 because a catch turned exceptions into a false result.

Why it matters

The number to notice is not the memory saving but how much code stopped earning its keep. With one process and one database, request-id tables and swallowed exceptions buy no resilience; they turn a validation failure into a 200. Five bugs in this reference app lived behind that pattern, so read it as a migration checklist, not a benchmark.

Before adopting it, verify no module still reads another's tables through raw SQL and that each test fixture tolerates one shared migration creating the pgvector extension. No data is migrated here; a live system needs export and import scripts. The payoff is a checkout path you can trace without a diagram.},

Real-world use

  • An application whose services already share one process and one database but still exchange domain events over RabbitMQ.
  • A background worker that polls another module's tables with raw SQL and has to move behind a contract interface.
  • Module-level functional tests that host a subset of modules and must still pass EF Core's migration checks.

This summary was generated by the agent from the original post on Habr C# (ru). The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message