dotnet/runtime

IOptions<T> should support C# records

ddrinka opened this issue · 4 comments

With PR #2169 in place, there is no longer a compiler restriction on using records with IOptions<T>. However the default OptionsFactory implementation still requires a parameterless constructor.

We should be able to use fully-defaulted records with the IOptions pattern. The following builds but throws:

record MyConfiguration(string value = "default");
MyConstructor(IOptions<MyConfiguration> configuration) { }

Feature request is already here: #43359

Tagging subscribers to this area: @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details

With PR #2169 in place, there is no longer a compiler restriction on using records with IOptions<T>. However the default OptionsFactory implementation still requires a parameterless constructor.

We should be able to use fully-defaulted records with the IOptions pattern. The following builds but throws:

record MyConfiguration(string value = "default");
MyConstructor(IOptions<MyConfiguration> configuration) { }
Author: ddrinka
Assignees: -
Labels:

area-Extensions-Options, untriaged

Milestone: -

@christiannagel Ok, looks like this is on the radar. Thanks for pointing me to that existing feature request.

Closing as dupe of #43359, thanks.