YairHalberstadt / stronginject

compile time dependency injection for .NET
MIT License
845 stars 24 forks source link

Natively support injecting IReadOnlyCollection<T> and ImmutableArray<T> #134

Closed jnm2 closed 3 years ago

jnm2 commented 3 years ago

It's nice if classes don't require a type that they can mutate (T[]). It's a small thing, but it could matter if the type is also used without StrongInject, for example in test code.

I use ImmutableArray<T> except in existing projects that can't or don't yet reference System.Collections.Immutable.

The reason I'm not asking about IReadOnlyList<T> is that I use that type instead of IReadOnlyCollection<T> when I want to imply that the index order is significant. I'm assuming that StrongInject doesn't have an ordering guarantee that is obvious to the reader since it could be collecting implementations from various separate files.

YairHalberstadt commented 3 years ago

You can get these types by importing the inbuilt StrongInject.Modules.StandardModule.

The reason I didn't make these automatically available is that at the time I found the model of how they would be user overridden complex to reason about. It may be that if I think about this a bit more I'll decide it's actually relatively straightforward.

jnm2 commented 3 years ago

Thanks! There are other things in there that I will want too. Could the error messages give this hint when the missing type is in the standard module?

YairHalberstadt commented 3 years ago

That's definitely a good option. It can on the backlog! :-)

jnm2 commented 3 years ago

Okay, I added it to the backlog. You can close this unless you would like to use this issue to track the further thought you mentioned.