Implement CQRS in ASP.NET Core Without MediatR

If you’ve worked with modern ASP.NET Core, you’ve almost certainly encountered MediatR. It’s a fantastic library, and for good reason; it has become the de-facto standard for implementing the CQRS pattern in .NET, helping you build clean, decoupled, and maintainable applications. But have you ever paused to look behind the curtain? In my experience building several lean microservices, I’ve found that while MediatR is a go-to, there are times when a simpler, handcrafted approach is more effective. This post is born from that experience. ...

November 10, 2025 · 6 min

ASP.NET Core Response Compression with Brotli & Gzip

Cut payload size by 60–80% in ASP.NET Core with built-in Brotli and Gzip compression. Step-by-step code, production tweaks, and real benchmarks.

October 23, 2025 · 4 min

Hybrid Caching Strategies Beyond MemoryCache in ASP.NET Core

Your app performs well with MemoryCache for 1K users. But when traffic scales to 10K users across three load-balanced servers, cache misses explode and response times spike to 800ms. I’ve seen production APIs crash under load because the team relied solely on MemoryCache. Here’s how we fixed it with hybrid caching strategies that combine the speed of local memory with the consistency of distributed cache. TL;DR MemoryCache works for single servers but fails in distributed environments Hybrid caching uses MemoryCache (L1) + Redis (L2) for best performance Multi-tenant apps need tenant-scoped cache keys to prevent data leakage System.Text.Json provides the best balance of performance and debuggability Monitor cache hit ratios per tenant and cache level for optimal tuning MemoryCache works great for single-server applications, but it hits hard limits in distributed environments. This guide covers hybrid caching strategies that keep your multi-tenant ASP.NET Core apps fast and scalable, with real benchmarks and production-ready code. ...

October 20, 2025 · 7 min

EF Core Interceptors for Secure, Per-Tenant Audit Logging

TL;DR In multi-tenant SaaS, generic audit logging can easily leak data between tenants. This is a security and compliance nightmare. Overriding DbContext.SaveChanges() is a common but clunky solution that tightly couples auditing logic to your data context. EF Core Interceptors provide a clean, decoupled way to hook into the save process and add per-tenant audit logs automatically. The solution involves creating a SaveChangesInterceptor, grabbing the current TenantId from a scoped service, and logging entity changes before they hit the database. This pattern is perfect for auditable, compliant SaaS applications but might be overkill for simple, single-server projects. I once got a panicked call about a critical bug. An admin from “Company A” could see user creation events from “Company B” in their audit trail. It was a classic multi-tenant data bleed, but not in the main application data—it was in the logs. This is one of those sneaky bugs that passes all unit tests but can absolutely destroy trust with your customers and fail a compliance audit. ...

October 3, 2025 · 8 min

5 ASP.NET Core DI Scope Mistakes Developers Must Avoid

Learn how to avoid common ASP.NET Core dependency injection lifetime mistakes. This guide covers DbContext misuse, scope leaks in singletons, transient performance traps, background service issues, and middleware lifetime bugs with real production fixes.

September 26, 2025 · 8 min

Should You Use UseRouting() or MapGet() First?

Learn why UseRouting() must always come before MapGet() in ASP.NET Core and how the middleware order impacts your request pipeline.

September 23, 2025 · 3 min

SaaS Middleware Anti-Patterns: What Not to Do in ASP.NET Core

Bad middleware doesn’t just break requests, it breaks entire tenants. Learn the anti-patterns to avoid in your ASP.NET Core SaaS architecture and how to fix them.

September 19, 2025 · 9 min

Code Reviews That Grow Developers

TL;DR Code reviews should teach, not just catch bugs. Stop nitpicking syntax and start building autonomous developers. Focus on architectural patterns, ask guiding questions instead of giving orders, and eliminate multi-team approval bottlenecks that delay delivery. Good reviews create learning opportunities that scale your team’s expertise. Code reviews shouldn’t be about catching syntax errors or enforcing personal preferences. They’re your best tool for spreading architectural knowledge and building stronger development teams. But most teams get this wrong, creating bureaucratic bottlenecks instead of learning opportunities. ...

September 16, 2025 · 7 min

ASP.NET Core: Auth with Middleware or Filters?

Discover how using custom middleware for authentication in ASP.NET Core SaaS APIs leads to cleaner, faster, and more maintainable code compared to traditional authorization filters.

September 12, 2025 · Last modified: September 19, 2025 · 3 min

Why Middleware Beats DI for SaaS Extension Points

In multi-tenant SaaS applications, custom middleware gives you the earliest hook in the request pipeline, even before dependency injection kicks in. Middleware runs at the very beginning of your pipeline, providing access to raw request data before any transformations occur.

August 24, 2025 · Last modified: August 28, 2025 · 9 min
×