public IHostBuilder UseServiceProviderFactory <TContainerBuilder>(Func <HostBuilderContext, IServiceProviderFactory <TContainerBuilder> > factory) where TContainerBuilder : notnull { Func <HostBuilderContext> contextResolver = () => this.hostBuilderContext !; if (factory == null) { throw new ArgumentNullException(nameof(factory)); } this.serviceProviderFactory = new ServiceFactoryAdapter <TContainerBuilder>(contextResolver, factory); return(this); }
/// <summary> /// Overrides the factory used to create the service provider. /// </summary> /// <param name="factory">A factory used for creating service providers.</param> /// <typeparam name="TContainerBuilder">The type of the builder to create.</typeparam> /// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns> public IHostBuilder UseServiceProviderFactory <TContainerBuilder>(Func <HostBuilderContext, IServiceProviderFactory <TContainerBuilder> > factory) { _serviceProviderFactory = new ServiceFactoryAdapter <TContainerBuilder>(() => _hostBuilderContext, factory ?? throw new ArgumentNullException(nameof(factory))); return(this); }
#pragma warning disable CS8714 // The type cannot be used as type parameter in the generic type or method. Nullability of type argument doesn't match 'notnull' constraint. public IAppHostBuilder UseServiceProviderFactory <TContainerBuilder>(IServiceProviderFactory <TContainerBuilder> factory) { _serviceProviderFactory = new ServiceFactoryAdapter <TContainerBuilder>(factory ?? throw new ArgumentNullException(nameof(factory))); return(this); }
public HostBuilder() { _serviceProviderFactory = new ServiceFactoryAdapter <IServiceCollection>(new DefaultServiceProviderFactory()); }