Scoped IComponentActivator breaks bUnit
See original GitHub issueI’m pretty sure the problem reported in the SO question below is due to Blazorise registering a IComponentActivator
as scoped, replacing our singleton registered BunitComponentActivator
. However, since the WebTestRenderer
is registered as a singleton it cannot be resolved.
The fix may be to register the renderer as a scoped service and all other dependent services like this too.
related: #1129
Issue Analytics
- State:
- Created 3 months ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Bunit & Blazorise Cannot consume scoped service ...
Replace(ServiceDescriptor.Transient<IComponentActivator, ComponentActivator>()); Other than that it should pretty much work out of the box. Let ...
Read more >bUnit/CHANGELOG.md at main
bUnit is a testing library for Blazor components that make tests look, feel, ... Allow using 3rd party IComponentActivator at the same time...
Read more >Injecting services into components under test
It is common for components under test to have a dependency on services, injected into them through the @inject IMyService MyService syntax in...
Read more >Newest 'blazorise' Questions - Stack Overflow - OpenQM
I am receiving this error to do a unit test with spec test and bunit for a project in Blazor and Blazorise: Cannot...
Read more >[Solved]-Blazor: Cannot initialize a ComponentBase more than once ...
Inside the IComponentActivator constructor i load the registered Pages once (into a ... InvalidOperationException: Cannot consume scoped service 'Microsoft.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, but singleton services can not depend on scoped services. Like the
BunitHtmlParser
that is a singleton, can not depend onTestRenderer
that is a scoped service.Anyway - making everything scoped would be my preferred anyway. Technically it wouldn’t change much the majority of use cases.
I’ll quote the official Blazorise docs:
That said, that would help the person in question on SO.