Dependency Injection in ASP.NET Core
summary
Microsoft.Extensions.DependencyInjection provides a minimal DI surface with IServiceCollection for registrations and IServiceProvider for resolution, implements three lifetimes Singleton/Transient/Scoped, and disposes scope services automatically at request end. Demo registers services, shows singletons persist, transients differ each resolve, scoped reuse per HTTP request, and disposal on scope end works. External containers integrate by reading the service collection (eg Autofac Populate or Castle Windsor bridge) to return an IServiceProvider and add features like interception, factories, open generics and custom lifetime policies.
AI-written summary · about
chapters (10)
- 0:00Introduction and motivation
- 3:17Built-in DI in ASP.NET Core
- 18:00External DI containers comparison
- 22:22Basic DI configuration demo
- 33:05Integrating external containers
- 39:55Best practices for DI usage
- 42:10When to use built-in vs external containers
- 44:20Service locator pattern discussion
- 46:44DI vs dependency inversion explained
- 48:35Q&A and closing
