How can "services" and "configurationRoot" be accessed in the same call ?
The following code appears multiple times on the page,
services.Configure<TransientFaultHandlingOptions>(
configurationRoot.GetSection(
key: nameof(TransientFaultHandlingOptions)));
The problem is that we have access to the "services" collection only in the body of delegate passed to IHostBuilder.ConfigureServices() .... when we make the following call:
IHostBuilder.ConfigureServices((hostBuilderContext , services) =>
// here we have access to "services")
While the configurationRoot is obtained after we call IConfigurationBuilder.Build() in the body of the delegate passed to IHostBuilder.ConfigureAppConfiguration(). That is when we have the the following:
IHostBuilder.ConfigureAppConfiguration( (hostBuilderContext, configurationBuilder) =>
{
// app configuration code ...
// now obtaining configurationRoot from configurationBuilder
IConfigurationRoot configurationRoot = configurationBuilder.Build();
// here we have access to "configurationRoot"
}
)
In short , the IServiceCollection "services" and the IConfigurationRoot "configurationRoot" are available in the bodies of two different delegates passed to two different methods on the IHostBuilder. How can they occcur in the same call ?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 433988ea-fda9-aa83-f6ee-221a5521a422
- Version Independent ID: 00449cdc-b8fc-a9ff-3f20-0ef0994db354
- Content: Options pattern in .NET
- Content Source: docs/core/extensions/options.md
- Product: dotnet-fundamentals
- GitHub Login: @IEvangelist
- Microsoft Alias: dapine
Hi @explorest - good observation, see #24755