Azure / AppConfiguration

Questions, feedback and samples for Azure App Configuration service
MIT License
241 stars 73 forks source link

How to use dependency injection to configure client options using AddAzureAppConfiguration() #995

Open chwilliamson opened 4 days ago

chwilliamson commented 4 days ago

Hi, I would appreciate some advice using dependency injection with AddAzureAppConfiguration().

Below is a snippet to help explain my question.

How would someone retrieve an instance of httpClientFactory from the services container?

var builder = WebApplication.CreateBuilder(args);
// Adds the IHttpClientFactory and related services to the service collection.
builder.Services.AddHttpClient();

builder.AddAzureAppConfiguration(options => {
     //  How to get a httpClientFactory from services?
     options.ConfigureClientOptions(co => co.Transport = new HttpClientTransport(httpClientFactory.CreateClient("AppConfigClient")));
});

// more code

Thank you.

drago-draganov commented 1 day ago

Unfortunately, DI is not available before the configuration is resolved.

Perhaps you may be interested in a new, related feature we recently added.

Give the users the ability to have control over ConfigurationClient instance(s) used by the provider https://github.com/Azure/AppConfiguration-DotnetProvider/pull/598