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

IOptions<T> should support C# records #46996

Closed
ddrinka opened this issue Jan 14, 2021 · 4 comments
Closed

IOptions<T> should support C# records #46996

ddrinka opened this issue Jan 14, 2021 · 4 comments
Labels
area-Extensions-Options untriaged New issue has not been triaged by the area owner

Comments

@ddrinka
Copy link

ddrinka commented Jan 14, 2021

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) { }
@christiannagel
Copy link

Feature request is already here: #43359

@dotnet-issue-labeler dotnet-issue-labeler bot added area-Extensions-Options untriaged New issue has not been triaged by the area owner labels Jan 14, 2021
@ghost
Copy link

ghost commented Jan 14, 2021

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: -

@ddrinka
Copy link
Author

ddrinka commented Jan 15, 2021

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

@maryamariyan
Copy link
Member

Closing as dupe of #43359, thanks.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-Options untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants