Skip to content

IServiceCollection Configure should have an overload taking Func<TOptions> #85276

Closed as not planned

Description

@jez9999

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I'm not exactly sure why, but at the moment the only way of setting up options with a factory in ASP.NET is to take an unconfigured instance of an options object, and modify it to have the correct values. There doesn't appear to be a way to just return the options object from the factory.

Describe the solution you'd like

There should be an overload in OptionsServiceCollectionExtensions of Configure that takes a Func<TOptions> so I can just return an options set instead of having to map each value manually. I have an overarching options object I first bind, then configure subsets of that options object that may need to be pulled in. Currently I need to do this:

private readonly WebAppOptions _options = new();

[...]

_conf.Bind(_options);
services
	.Configure<WebAppOptions>(_conf);
services
	.Configure<TurnsProcessorOptions>(opts => {
		opts.EmptyRoundsForGameDraw = _options.TurnsProcessorOptions.EmptyRoundsForGameDraw;
		opts.TurnTimeoutInterval = _options.TurnsProcessorOptions.TurnTimeoutInterval;
	});

A Func<TOptions> overload would allow me to simply do:

_conf.Bind(_options);
services
	.Configure<WebAppOptions>(_conf);
services
	.Configure<TurnsProcessorOptions>(() => _options.TurnsProcessorOptions);

Additional context

No response

Activity

  1. transferred this issue fromdotnet/aspnetcoreon Apr 24, 2023
  2. ghost added
    untriaged
    on Apr 24, 2023
  3. added this to the Future milestone on Apr 25, 2023
  4. ghost removed
    untriaged
    on Apr 25, 2023
  5. added
    api-suggestion
    on Apr 25, 2023
  6. modified the milestones: Future, 11.0.0 on Mar 17, 2026
  7. rosebyte commented on Mar 17, 2026

    @rosebyte
    Member

    Triage: we don't see any usecase for this feature shared and in general the idea sounds interesting but rather niche. There is an obvious workaround using a custom IOptionsFactory implementation.

  8. locked and limited conversation to collaborators on Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionarea-Extensions-Options

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions