bUnit
bUnit copied to clipboard
bUnit's ServiceProvider API surface is missing `GetScopedService<T>()`
Describe the Bug
As I mentioned in #847, our product added the ability to be a FallbackServiceProvider for bUnit.
The problem now is that, your IServiceProvider implementation is missing the ability to get Scoped services in a way that also tries to pull them from the failover ServiceProvider. My existing testing codebase has a number of scoped services that fail to resolve after we switched to the Failover model.
Expected Behavior:
Because the implementation blocks access to the underlying built IServiceProvider, I would expect that the API surface allows users to retrieve scoped services explicitly.
Requested Fix:
We would like you to please add methods to your API surface, similar to our implementation here, that allows for explicit scoped service resolution.
We would also request that you consider having your non-scoped service resolution to be modfied to attempt to pull from the default scope before attempting to pull from the FailoverServiceProvider. (You could potentially write a warning to the console if the service was pulled from the default scope.)
Version info:
bUnit version: Latest .NET Runtime and Blazor version: 6.x OS type and version: Windows 11
Hi Robert,
I am not sure I understand what we can change.
Our TestServiceProvider implements IServiceProvider, which only has a single method, GetService.
If a service is not found, it tries to find it in a fallback service provider, if any, and it just does that through a call to `'GetService' on the fallback service provider.
The GetService method does not care how the service was registered, be it singleton, scoped, or trancient, it just returns the service if it can.
Can you elaborate a bit more, thanks.
Closing this issue due to inactivity.