Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static IHostBuilder CreateHostBuilder(string[] args) =>
- Host.CreateDefaultBuilder(args)
- .ConfigureAppConfiguration(configurationBuilder =>
- {
- // nothing to do here
- })
- .ConfigureHostConfiguration(configurationBuilder =>
- {
- // nothing to do here
- })
- .ConfigureServices((hostBuilderContext, serviceCollection) =>
- {
- IConfigurationSection myConfigurationSection = hostBuilderContext.Configuration.GetSection("app");
- serviceCollection.AddSingleton<IValidateOptions<AppOptions>, AppOptionsValidator>();
- serviceCollection.Configure<AppOptions>(myConfigurationSection);
- // ! Just for testing purposes !
- IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
- IOptions<AppOptions> appOptions = serviceProvider.GetService<IOptions<AppOptions>>(); // appOptions threw a Microsoft.Extensions.Options.OptionsValidationException
- AppOptions x = appOptions.Value;
- string y = x.Foo;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement