Skip to content

How to hook up alternate IServiceProvider implementation? #5646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DaRosenberg opened this issue Nov 18, 2018 · 2 comments
Closed

How to hook up alternate IServiceProvider implementation? #5646

DaRosenberg opened this issue Nov 18, 2018 · 2 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@DaRosenberg
Copy link

I'm trying to hook Autofac into my Blazor app, but I can't find any way to provide the actual IServiceProvider instance myself.

Here's an illustration of what I'm trying to do (as per Autofac documentation):

public class Startup
{
    public IContainer ApplicationContainer { get; private set; }

    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        var builder = new ContainerBuilder();
        builder.Populate(services);
        // Add some custom service and implementation to test whether it can be injected
        builder.RegisterType<DefaultSystemClock>().As<ISystemClock>();
        ApplicationContainer = builder.Build();

        // This return value seems to never be used by the WebAssemblyHostBuilder
        return new AutofacServiceProvider(ApplicationContainer);
    }

    public void Configure(IBlazorApplicationBuilder app)
    {
        app.AddComponent<App>("app");
    }
}

A quick glance into the source of WebAssemblyHostBuilder and ConventionBasedStartup seems to confirm that this is not how it's implemented (there's no code that take care of any return value from the ConfigureServices() method.

Is there some other hook I should be using to replace the default IServiceProvider implementation with the one provided by Autofac?

@csnewman
Copy link

Custom service providers are not current supported. However I have a PR #1623 open to enable support.

Also, I have Autofac working using my proposed changes.

@aspnet-hello aspnet-hello transferred this issue from dotnet/blazor Dec 17, 2018
@aspnet-hello aspnet-hello added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-blazor Includes: Blazor, Razor Components labels Dec 17, 2018
@SteveSandersonMS
Copy link
Member

Implemented in #4785

@mkArtakMSFT mkArtakMSFT removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

5 participants