Skip to content

Add overload of UseServiceProviderFactory that takes a delegate #612

Closed

Description

@davidfowl

If you want to configure the DI factory based on the hosting environment the current methods makes it pretty impossible to do so. Unlike the other methods that take a delegate, these don't compose very well and the last delegate wins.

The WebHostBuilder implementation is currently sorta hacky and likely broken in subtle ways because of this:

https://github.com/aspnet/AspNetCore/blob/926034ac4eed763cf7baf4acaeccba3272738d46/src/Hosting/Hosting/src/GenericHost/GenericWebHostBuilder.cs#L197-L212

API proposal (breaking API change)

public interface IHostBuilder
{
    IHostBuilder UseServiceProviderFactory<TContainerBuilder>(Func<HostBuilderContext, IServiceProviderFactory<TContainerBuilder>> factory);
}
var host = new HostBuilder()
                      .UseServiceProviderFactory((context) =>
                      {
                             var options = new ServiceProviderOptions() { ValidateScopes = context.HostingEnvironment.IsDevelopment() };
                             return new DefaultServiceProviderFactory(options);
                      });

Activity

  1. added this to the 3.0.0-preview2 milestone on Dec 10, 2018
  2. davidfowl commented on Dec 10, 2018

    @davidfowl
    MemberAuthor
  3. self-assigned this
    on Dec 10, 2018
  4. davidfowl commented on Dec 13, 2018

    @davidfowl
    MemberAuthor

    When you add the API fix the web host as well.

  5. ghost locked as resolved and limited conversation to collaborators on Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions