Question

Unity's InjectionConstructor works well when you need to invoke a specific constructor because you have very specific dependencies in mind (e.g. any mix of external dependencies, named registrations, or unnamed registrations), but it requires all parameters to be specified.

Is there some way to augment Unity's "find and use the constructor with the most number of parameters" with "find and use the constructor with the most number of parameters that also could accept an instance of IX somewhere in the signature"?

Was it helpful?

Solution

Mark's comment provided the basis for the answer. Namely, the implementation of AddPolicies

  • has to find a constructor that matches all of the values (explicit) I pass into the constructor of InjectionConstructor. There are limitations (e.g. if the values are null or they get matched against a supertype in a constructor), and
  • for the remaining (implicit) ones, use the container to resolve them.

I'm not saying this is good though. I ultimately used RegisterInstance elsewhere and the mixed-parameter need went away. But it's a solution for those who might need it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top