-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Support immutable collections (System.Collections.Immutable) in options binding (ConfigurationBinder) #78592
Comments
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsConsider the following app settings and corresponding options class: // app.settings
{
"MyStrings": ["a", "b", "c"]
} public class MyOptions
{
public ImmutableArray<string> MyStrings { get; set; }
//or ImmutableHashSet<string>, or ImmutableDictionary<string,string>, etc.
} Following a Line 1272 in 0f3a88b
However, even assuming the client does not cast away the immutability, it's not as good as Immutable without any guarantee on the generated underlying type. This is specifically problematic when considering thread safety (which a readonly interface does not guarantee). Plus these is no
|
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsRelated issue: dotnet/dotnet-api-docs#8658 (Possible threading issues with non thread safe collections in Options classes) Consider the following app settings and corresponding options class: // app.settings
{
"MyStrings": ["a", "b", "c"]
} public class MyOptions
{
public ImmutableArray<string> MyStrings { get; set; }
//or ImmutableHashSet<string>, or ImmutableDictionary<string,string>, etc.
} Following a Line 1272 in 0f3a88b
However, even assuming the client does not cast away the immutability, it's not as good as Immutable without any guarantee on the generated underlying type. This is specifically problematic when considering thread safety (which a readonly interface does not guarantee). Plus these is no
|
Related to #44493. This seems like an enhancement request. @dotnet/area-extensions-configuration @davidfowl @ericerhardt it looks like a plethora of collection types are supported for configuration binding. How do we determine what types to support? Do we want collection support in the .NET 8 version of the |
If I could offer my 2 cents, considering the nature of options classes in general and their ASP.NET usage specifically, I think the concurrent readonly scenario is extremely common. Recall that options classes are cached which means virtually all DI consumers would get the same options class instance (for example, each controller instance created for a request). This basically makes it a concurrent scenario automatically (where readonly is virtually assumed). While it is true that |
Related issue: dotnet/dotnet-api-docs#8658 (Possible threading issues with non thread safe collections in Options classes)
Consider the following app settings and corresponding options class:
Following a
ConfigurationBinder.Bind
call, the immutable array above is not bound (itsIsDefault
istrue
).Indeed, this does not seem to be supported, where the closest thing I could find was read-only collection binding:
runtime/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/ConfigurationCollectionBindingTests.cs
Line 1272 in 0f3a88b
However, even assuming the client does not cast away the immutability, it's not as good as Immutable without any guarantee on the generated underlying type. This is specifically problematic when considering thread safety (which a readonly interface does not guarantee). Plus these is no
ReadOnlySet<T>
AFAIK (#29387).The text was updated successfully, but these errors were encountered: