docs icon indicating copy to clipboard operation
docs copied to clipboard

How can "services" and "configurationRoot" be accessed in the same call ?

Open explorest opened this issue 5 years ago • 1 comments

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.

explorest avatar May 11 '21 12:05 explorest

Hi @explorest - good observation, see #24755

IEvangelist avatar Jun 21 '21 15:06 IEvangelist