You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Without the init-accessor feature I would prefer construtor injection over property injection, because for the latter the property would need to become mutable. In my opinion the init-accessor is changing the game. In the example above, if constructor-injected, then the constructor would initialize a readonly field or get-only property anyway. So by supporting init-accessor the dependency could be injected into the "get-only" (of course there is also the init) property right away.
Additionally, that way the dependencies which are not relevant for the constructor but later on could be separated from the constructor.
One little caveat is of course that the init-injected properties cannot be used in the constructor, because they'll be initialized by the runtime after the constructor run through.
The text was updated successfully, but these errors were encountered:
Init properties can only be set at construction, but don't have to be set. Required properties have to be set at construction.
As such I think it makes more sense to wait for required properties and support them, than to support init properties.
We could view init properties as optional dependencies, i.e. - if we have something that can provide it then use that, otherwise ignore it, but I'm not sure if that would be best for users or not.
Hi, I think it would be awesome if the C# 9.0 init-accessors for properties would be supported. Consider following example:
Without the init-accessor feature I would prefer construtor injection over property injection, because for the latter the property would need to become mutable. In my opinion the init-accessor is changing the game. In the example above, if constructor-injected, then the constructor would initialize a readonly field or get-only property anyway. So by supporting init-accessor the dependency could be injected into the "get-only" (of course there is also the init) property right away.
Additionally, that way the dependencies which are not relevant for the constructor but later on could be separated from the constructor.
One little caveat is of course that the init-injected properties cannot be used in the constructor, because they'll be initialized by the runtime after the constructor run through.
The text was updated successfully, but these errors were encountered: