Skip to content

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Latest articles

3 min read

Why You Can't Inject Scoped Services in Middleware Constructors (And How to Fix It)

ASP.NET Core middleware is instantiated once at startup, so injecting Scoped services like DbContext in the constructor causes captive dependency—shared instances across requests lead to connection pool exhaustion and data corruption; instead, inject Scoped services via InvokeAsync parameters to get per-request instances.