What is the order of applying different injection methods?

May 26, 2011 at 2:37 PM

Unity Application Block allows for 3 methods of dependency injection: in a construtor, by properties and by a injection method.

Is it possible to determine what is the order of injection?

I guess the constructor injection is performed first. But what then?

Can I assume that a property with a [Dependency] attribute will have the dependency injected before the method with [InjectionMethod] attribute will be invoked?

I cannot find any information about the order of performing the injection.

May 26, 2011 at 8:34 PM

It's constructor (of course) first, then properties, then methods. But this isn't a spec, just the way it's current implemented, and therefore could change in future releases.

Also, there are no guarantees on the ordering of property sets or method calls - depending on how it's configured and what reflection gives you, it may set property A, then B, then C, or C, B, A, or C, A, B, or whatever order.



May 27, 2011 at 11:48 AM

Thanks for the answer! It helped to make a decision. As it is not in the specification, we will not count on that order.