FallbackProvider is not called. #722
Unanswered
OrionRiftStudios
asked this question in
Q&A
Replies: 3 comments 3 replies
-
Hi there, It's certainly not expected. Can you share the test (and setup plus relevant fallback service provider) code and the component? Otherwise it's hard to help. Ideally share a minimal example, e.g. an empty component with just the |
Beta Was this translation helpful? Give feedback.
0 replies
-
I just tried to reproduce the issue and at least on my end with a minimal setup ,everything works as expected: public class FallbackServiceRendererTest : TestContext
{
[Fact]
public void HuppsyWuppsyNoThrowyOwy()
{
var servicesCollection = new ServiceCollection();
servicesCollection.AddScoped<IService>(_ => new NoopService());
Services.AddFallbackServiceProvider(servicesCollection.BuildServiceProvider());
Services.GetService<IService>().ShouldBeOfType<NoopService>();
Action act = () => RenderComponent<ComponentWithFallback>();
act.ShouldNotThrow();
}
private class ComponentWithFallback : ComponentBase
{
[Inject] IService Service { get; set; }
protected override void OnInitialized()
{
Service.Noop();
}
}
private interface IService
{
public void Noop();
}
private class NoopService : IService
{
public void Noop() { }
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you for your response I updated my original post. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello.
First of all thank you for this amazing framework.
I have a question. (Maybe this is a bug)
I'm using FallBackProvider to inject some services I need in my razor component.
If I use
TestContext.Services.GetService the FallBackProvider is executed as expected.
If I use
TestContext.RenderComponent<mycomponent>
my component has some services that must be resolved by the FallBackProvider.The FallBackProvider is never called.
I think this is a potential bug.
Do you know how to solve this issue ?
Here is the code I am using :
I am trying to load all the services I need for running my integration tests
The idea is TestBase is building the host and running the TestServer BUnit will load the views and find the missing services from the Host I am using Constructor Injection for the Views replacing the IComponentActivator in my application(normal execution) this is working fine I am using this library
https://github.com/TanvirArjel/TanvirArjel.Blazor
BUnit successfully can load the View but cannot inject the services in the constructor the exception is IViewModel cannot be injected because the concrete class was not found.
but if I use ctx.Services.GetService it works.
this is the Test Class
Thank you
Beta Was this translation helpful? Give feedback.
All reactions