.NET Core Dependency Injection – The Booster Jab
summary
Covers concrete pitfalls and workarounds for the built‑in Microsoft DI: singleton constructors can capture scoped or transient instances and leak them for app lifetime; middleware singletons resolve scoped services from the root provider; use UseServiceProviderFactory to plug in Autofac and ConfigureContainer for its modules; emulate named/key resolution with a string→implementation delegate (example: temperature converters) and use custom delegates for testable DateTime. Shows factory/builder patterns, Scrutor assembly scanning, IHostApplicationLifetime for disposing hand‑created instances, and a hosted warm‑up service to improve startup JIT and singleton readiness.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 7:02Lifetimes
- 14:13Scope
- 25:00registration
- 27:44hints and tricks
- 34:18design patterns
- 41:18runtime error
- 41:50value types
- 42:13record types
- 42:57custom delegates
- 46:07delegate example
- 46:50antipattern
- 47:49example
- 48:12delegate
- 49:03consumer
- 49:35decorator
- 51:19registration services
- 52:18performance
- 53:19wrap up
related talks
27mDemystifying Dependency Injection Containers
45mInversion of Control Containers Beyond Constructor Injection
59mCustomizing ASP.NET Core
24mDependency Injection at Scale
49mDependency injection from zero to hero with Koin
01h 01mAn Opinionated Approach to Using ASP.NET Core
42mASP .NET Basics for Experts
43mDependency Injection Pattern for iOS App
