0
votes

I have a server side blazor application and I'm also using simple injector for other dependency injections in my application.

I want to register all services from blazor to the simple injector container because otherwise I will have to duplicate all service registration but also the main problem is that there's some services registrations that I don't know what is the correct way of registering (usually comes from some dependency injection extension library).

For example, I need something like

public void ConfigureServices(IServiceCollection services)
{
    // multiple service registration
    services.RegisterSomeServices();
    // ... 

    // some how register all services into simple injector container
    container.SomeHowRegisterServices();
}

How can I get all registered services from blazor and register in the simple injector container?

1
There are some discussions on integration, but at the time of writing, there is still no official guidance on how to properly integrate Simple Injector with Blazor components. - Steven

1 Answers

0
votes

After some time searching, I found in the docs a ServiceCollection Integration Guide which is a way of integrating third party services into the Simple Injector.

What I need to do according to Cross wiring framework and third-party services is cross wire blazor services into simple injector, so for my case, what I need to do is

public void ConfigureServices(IServiceCollection services)
{
    // multiple service registration
    services.RegisterSomeServices();
    // ... 

    // some how register all services into simple injector container
    IServiceProvider provider = services
        .AddSimpleInjector(simpleInjectorContainer)
        .BuildServiceProvider(validateScopes: true);

    // Ensures framework components are cross wired.
    provider.UseSimpleInjector(simpleInjectorContainer);
}