[coldbox:13133] Dependency injection by configuration

"I'm not really a fan of the annotation approach because it requires that the components I'm creating know about the structure of the object they are to receive their injected properties from."

Could you elabrate on that? If I have the following property in a component:
<cfproperty name="userService" inject="model:userService">

then the only thing my component has to know is that is is dependant upon a model object called userService. Is that really too much for the component to be expected to know, or are you injecting something differently?



Thanks, Luis. I'll give it a look.
Brad, the reason I don't like to set up the injection this way is
because it hard-wires the value of each property to the model, making
the classes not resilient to change. If I have classes A, B, and C set
up all using inject="model:userService", and later I find that A and B
should really depend on another service, I have to change the
cfproperty tag in both of those classes to achieve that. I would
rather edit a few lines in a configuration file (like the IOC
container in Spring) to make this kind of change.

Just for a quick devil's advocate point for those reading along:

I think it is more helpful to have the annotation in the class itself
that way it is obvious, within the class itself, what that class
depends on. If you are doing all your configuration elsewhere and
telling the DI engine "go find this class and inject X, Y and Z into
it" there is the advantage that if you want to change that to only X
and Q, that's easy to do all your mappings in one place. On the other
hand, when you are looking at your class, you see references to
classes with names that (due to mappings) might not correspond to any
physical file name and there is nothing within your class that tells
you where it comes from. Furthermore, if you pull out a class that
your service no longer needs to rely upon, you're changing that
service anyway, so I don't see that it is any more burden to change
the annotations in that service vs in the main configuration file.

In short, I think that the annotation approach provides better
documentation within a service/class/etc, making it easier on someone
who is maintaining the code to get a clear overview of the service's
dependencies without having to go searching through multiple files.