Based on your experience with Marten and Wolverine, here are some key takeaways and best practices:
-
Event Sourcing vs Document Store:
- Use event sourcing for entities that require a temporal log (audit trails, replay capabilities).
- For other entities, use Marten's document store feature to save plain POCOs as JSONB documents.
-
Handler Design:
- Avoid reaching for
IMessageBus.PublishAsyncmid-handler; instead, return cascading messages from your handler. - Handlers should be pure functions that return side effects (like database operations and message publications).
- Avoid reaching for
-
Session Management:
- Use
IQuerySessionfor read-only queries to avoid change tracking issues. - Use
IDocumentSessionfor read-modify-write scenarios.
- Use
-
Avoid Overusing MediatR Patterns:
- If your handler is just delegating to a service, consider whether it's necessary or if you can simplify by writing a controller method directly.
-
Query Performance Optimization:
- Default to query plans and only promote to compiled queries when profiling shows significant performance benefits.
- Be cautious with bulk insert operations as they bypass inline projections; ensure your
Read the full article at DEV Community
Want to create content about this topic? Use Nemati AI tools to generate articles, social posts, and more.

![[AINews] The Unreasonable Effectiveness of Closing the Loop](/_next/image?url=https%3A%2F%2Fmedia.nemati.ai%2Fmedia%2Fblog%2Fimages%2Farticles%2F600e22851bc7453b.webp&w=3840&q=75)



