Рет қаралды 9,150
Get the source code for this video for FREE → the-dotnet-weekly.ck.page/sco...
☄️ Master the Modular Monolith Architecture: bit.ly/3SXlzSt
📌 Accelerate your Clean Architecture skills: bit.ly/3PupkOJ
🚀 Support me on Patreon to access the source code: / milanjovanovic
Did you ever need to inject a scoped service into a singleton service? I often need to resolve a scoped service, like the EF Core DbContext, in a background service. Another example is when you need to resolve a scoped service in ASP.NET Core middleware. If you ever tried this, you were probably greeted with an exception. In this video, I'll explain how you can solve this problem and safely use scoped services from within singletons in ASP.NET Core.
Check out my courses: bit.ly/3PupkOJ
Using Scoped Services From Singletons in ASP.NET Core
www.milanjovanovic.tech/blog/...
Join my weekly .NET newsletter:
www.milanjovanovic.tech
Read my Blog here:
www.milanjovanovic.tech/blog
Chapters
0:00 Injecting Scoped services in Background jobs
3:07 Resolving Scoped services with IServiceScopeFactory
4:55 IServiceProvider vs IServiceScopeFactory
6:08 Injecting Scoped services in Middleware