I followed the guidelines in the docs regarding scoped DI in behaviors and I’m unexpected things. I need to resolve a scoped dependency in behavior so I went and tried to get it from context.Builder. This results in a “Cannot resolve scoped service ‘ITerminalContext’ from root provider” exception. Seems correct since the ServiceProvider is indeed not scoped:
I tried to test this setup on the ASP.NET Core Dependency Injection Integration sample and this gives me the exact same result. Trying it on the MultiTenantDI example, where the endpoint is not hosted in the Microsoft Generic Host, it does work.
The modified sample running in the Microsoft Generic Host can be found here: GitHub - sylvaingirardbe/nsb-scoped-di-repro
Is this a bug?