The Right Way To Use Scoped Services From Singletons in ASP.NET Core
Milan Jovanović
0:00 / 0:00
The Right Way To Use Scoped Services From Singletons in ASP.NET Core
17 311 просмотров · 2 года назад
Milan Jovanović
168 тыс. подписчиков
17 311 просмотров · 2 года назад
Get the source code for this video for FREE → https://the-dotnet-weekly.ck.page/sco...
☄️ Master the Modular Monolith Architecture: https://bit.ly/3SXlzSt
📌 Accelerate your Clean Architecture skills: https://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: https://bit.ly/3PupkOJ
Using Scoped Services From Singletons in ASP.NET Core
https://www.milanjovanovic.tech/blog/...
Join my weekly .NET newsletter:
https://www.milanjovanovic.tech
Read my Blog here:
https://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