Open NetherGranite opened 1 year ago
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection See info in area-owners.md if you want to be subscribed.
Author: | NetherGranite |
---|---|
Assignees: | - |
Labels: | `area-Extensions-DependencyInjection` |
Milestone: | - |
This will be interesting for other container owners to follow since the conforming container may require it. If anything changes, there should be some container compatibility tests added for it.
@tannergooding @SingleAccretion @jkotas @VSadov @stephentoub
Hi all - Do you have any insight into future plans regarding dependency injection and required
properties? AutoFac DI is considering adding support for injecting into required
properties but would like to do so in a way that is compatible with any plans for Microsoft's DI. I'm an AutoFac user and would really love this feature.
There's currently no plan to add it, but I'd be interested in what the other DI container plan to do here (if anything).
Simple Injector is not going to support this OOTB, but we allow users to plug this in via already existing extension points.
Autofac is adding it but there's some thought going into whether or not a property marked required
yet also has nullable reference type markings indicating it can be nullable should thus be considered optional ("resolve it if you can, set null if you can't").
Just to note that we just shipped v7 of Autofac with required property support; our documentation for required properties goes into the caveats and approach taken for handling various cases (e.g. where constructors and properties are mixed).
Just wanted to bump this issue as work on .NET 9.0 has started.
Required property injection is an awesome feature in Autofac as it eliminates tons of boilerplate code, especially where an inheritance hierarchy exists.
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
Property injection is not supported in the default service container, but now required members are coming with C# 11.
Describe the solution you'd like
Property injection like in legacy ASP.NET via something like an
InjectAttribute
could be valuable. Maybe required members should even be automatically detected.Additional context
I was not able to find any reasoning as to why property injection was omitted in ASP.NET Core's default service container, so I don't know if the fact that property injection was considered a design issue since it makes dependencies optional was a factor.
If it was a factor, a lot of ASP.NET Core boilerplate could be massively reduced via property injection the way required members will now reduce constructor boilerplate.