-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-Extensions-Optionsfeature-request
Milestone
Description
Today the IOptions<TOptions> pattern is built around the mutability of the TOptions until first use (though nothing prevents later mutation). We should investigate what it would mean to consume immutable TOptions in the options system. Today, the system constructs TOptions using Activator.CreateInstance then executes a series of delegates on top of that instead to produce the "final" instance (see
| public TOptions Create(string name) |
An alternative model would be to do the same thing but execute delegates that return a new instance of the options object instead of mutating the current instance. We would need to figure out how to support both side by side but it would allow designing immutable options objects.
Here's an example of what we what it would look like:
public record MyImmutableOption(string Name, int Size);
public void ConfigureServices(IServiceCollection services)
{
services.Configure<MyImmutableOption>(o =>
{
return o with { Name = "Foo" };
});
}JanEggers, christiannagel, seangwright, loraderon, DillonN and 64 more
Metadata
Metadata
Assignees
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-Extensions-Optionsfeature-request