Closed TonyValenti closed 5 months ago
Is there a reason you cannot use IReadOnlyList<Bar>
?
public class Foo {
public required IReadOnlyList<Bar> Data {protected get; init; }
}
That works out-of-the-box, and provides most of the same semantics as immutable data structures provided you don't reflect over the underlying structure.
@alistairjevans With the immutable structures I get non-destructive mutations which I don't get with the IReadOnlyList. IReadOnlyList is basically only a pre-enumerated enumerable.
Are you modifying lists of injected services after they are injected? You might have to provide a fuller example here, not sure I understand.
Hi @alistairjevans - No, we're not doing any modifications to them. We just prefer using ImmutableArray/ImmutableList over IReadOnlyCollection.
Duplicate #1408
Problem Statement
We have code like this:
And we'd like to replace it with code like this:
But Autofac does not know how to construct an
ImmutableArray
orImmutableList
.Desired Solution
Please teach Autofac how to construct those types as a replacement for IEnumerable.
Alternatives You've Considered
I could do this:
But it does not have the same characteristics as Immutables.