-
Notifications
You must be signed in to change notification settings - Fork 25
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 init-accessor of properties #113
Comments
In the future CSharp plans to support required properties. dotnet/csharplang#3630 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. |
Didn't know about this proposal. Considering that, you are right the required properties would be a better fit for what I suggested. |
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: