Why attributes to signal dependency injection?

Topics: CAB & Smart Client Software Factory
Aug 15, 2005 at 10:15 PM
originally posted by: WardBell

I'm curious about the decision to place attributes above private member variables to signal to the CAB where to inject implementation objects. At least that's what it looked like on the web cast of 8/12. I can guess why ... but it smells funny.
Constructor injection and setter injection strike me as more intuitive (granted the danger that someone will re-set the object by calling the setter twice). And with all of those attributes running around, how do you know you haven't missed one?
I understood it when attributes were used to communicate something exogenous to the purpose of the code (e.g., serialization and browsability). NUnit comes along and uses them to identify tests. Now you're using them to identify (to a compositing component) the plugins to its template methods? Does this have something to do with taking a declarative as opposed to a programmatic approach to code development?
Like I said, I'm curious ... not critical.
Aug 19, 2005 at 4:44 AM
originally posted by: BradWilsonMSFT

In the drop of CAB available today, we can do property setter injection with the same attribute. We've gotten feedback that doing injection on private fields does feel wrong, so it's possible that we'll remove this feature (and only permit injection on public fields and properties).

We are also looking into adding constructor injection, which is not available in the current drop.