Skip to content

Make ConfigurationOptions IDisposable #2922

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

Closed
wants to merge 1 commit into from

Conversation

philon-msft
Copy link
Collaborator

Creating this PR for discussion.

The main advantage of IDisposable ConfigurationOptions is it enables graceful shutdown of IDisposable default options providers like AzureCacheOptionsProviderWithToken, which has a token refresh Timer that should be stopped.

@NickCraver
Copy link
Collaborator

I'm not sure this makes sense given it doesn't own anything and a lot of people share options for the lifetime or for multiple multiplexers or pooling, so the IDE advice can be bad here instructing to dispose too.

I agree with the problem scenario, just don't think this is a good path to take trying to solve that category of stuff.

@mgravell
Copy link
Collaborator

mgravell commented Jul 22, 2025

The fact that the options and defaults provider often/usually have very different lifetimes makes this... awkward. It is not usually the cast that the two are linked, and most of the time this would be unnecessary and/or incorrect - making busy-work without need. I wonder whether there's some new wrapper API that we'd need instead, i.e.

public readonly struct NewWrapperNamingIsHard : IDisposable
{
    // wraps options+defaults provider

    public ConfigurationOptions Options => ...
    public static implicit operator ConfigurationOptions(NewWrapperNamingIsHard value) => value.Options;
}

so some API would return a NewWrapperNamingIsHard

@philon-msft
Copy link
Collaborator Author

Closing this. We'll use a different approach that relies on a new AfterDisconnectAsync() callback on DefaultOptionsProvider to shut down custom DefaultOptionsProviders when zero connections are using their ConfigurationOptions.

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

Successfully merging this pull request may close these issues.

3 participants