public void CanGetHostEnvironment() { var hostEnvironment = new Mock <IHostEnvironment>().Object; var configuration = new Mock <IConfiguration>().Object; var provider = new HostBuilderServiceProvider(configuration, hostEnvironment); var result = provider.GetService(typeof(IHostEnvironment)); Assert.NotNull(result); }
public void NullForAnyOtherServiceType() { var hostEnvironment = new Mock <IHostEnvironment>().Object; var configuration = new Mock <IConfiguration>().Object; var provider = new HostBuilderServiceProvider(configuration, hostEnvironment); var result = provider.GetService(typeof(HostBuilderServiceProviderTests)); Assert.Null(result); }
public static IHostBuilder UseStartup <T>(this IHostBuilder hostBuilder) where T : class, IWorkerStartup { return(hostBuilder.ConfigureServices((context, services) => { var provider = new HostBuilderServiceProvider(context.Configuration, context.HostingEnvironment); var startup = ActivatorUtilities.CreateInstance <T>(provider); startup.ConfigureServices(services); })); }
private static IServiceCollection AddCommandServiceStartup <TStartup>( this IServiceCollection services, IConfiguration configuration, IHostEnvironment hostEnvironment, Action <MariCommandsOptions> configureOptions) where TStartup : class, ICommandServiceStartup { var hostBuilderProvider = new HostBuilderServiceProvider(configuration, hostEnvironment); var commandStartup = ActivatorUtilities.CreateInstance(hostBuilderProvider, typeof(TStartup)) as ICommandServiceStartup; commandStartup.ConfigureServices(services); services.AddCommandStartup <TStartup>(configureOptions); return(services); }