Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IConfigurationRefresher instance available via DI #167

Closed
zhenlan opened this issue Jun 5, 2020 · 5 comments · Fixed by #184 or #185
Closed

Make IConfigurationRefresher instance available via DI #167

zhenlan opened this issue Jun 5, 2020 · 5 comments · Fixed by #184 or #185
Assignees
Labels
breaking change enhancement New feature or request

Comments

@zhenlan
Copy link
Contributor

zhenlan commented Jun 5, 2020

It's useful for user code to obtain the instance of IConfigurationRefresher so they can refresh configuration synchronously or write their own middleware etc.

Proposal

Add extension method below that user can call in ConfigureServices(...)

public static IServiceCollection AddAzureAppConfiguration(this IServiceCollection services)

Under the cover, this API will add IConfigurationRefresherAccessor to the DI.

public interface IConfigurationRefresherAccessor
{
    IEnumerable<IConfigurationRefresher> Refreshers { get; set; }
}

User code can then get the instances of IConfigurationRefresher (via IConfigurationRefresherAccessor) from the DI.

Note: the implementation of IConfigurationRefresherAccessor will need to get IConfiguration from DI and cast it to IConfigurationRoot etc, just like what we do in the middleware today.

Other Considerations

  • We may need to consider exposing other properties in IConfigurationRefresher so users can differentiate instances from one to another.
  • We may consider changing our middleware to obtain instances of IConfigurationRefresher in the same way. This means users must call AddAzureAppConfiguration before they can call UseAzureAppConfiguration.

cc: @abhilasharora @jimmyca15 @drago-draganov

@zhenlan zhenlan added breaking change enhancement New feature or request labels Jun 5, 2020
@drago-draganov
Copy link
Contributor

drago-draganov commented Jun 5, 2020

I don't think there is a need for IConfigurationRefresherAccessor. DI can inject IEnunmerable<IConfigurationRefresher> directly.

@zhenlan
Copy link
Contributor Author

zhenlan commented Jun 5, 2020

We need to run the code that we have in the middleware today to get IEnunmerable<IConfigurationRefresher>, which is the reason I think we need IConfigurationRefresherAccessor. I will be glad if we don't have to. I will leave this to @abhilasharora to find out.

@drago-draganov
Copy link
Contributor

It's a standard mechanism to add multiple instances of the same type T. Then the DI makes it available by requesting IEnumerable<T>

@abhilasharora
Copy link
Contributor

I already have PR #78 out for changes that provide this functionality. I sent it last year, but it seems for some reason we decided to put it on hold.

@abhilasharora
Copy link
Contributor

These changes are now available in version 4.0.0-preview of the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment