I've been looking at Google Guice. At first, I really didn't like the idea of using annotations to provide beans that describe their own DI requirements for my use case.
I use a Software Product Line approach with a single framework for generating all of my sites, and it is not uncommon for me to decide something like: "I'm going to inject another bean called %ObjectName%Mapper into all of my %ObjectName%Service beans". Such a change would be painful to make with annotations as I'd need to edit ALL of my beans in all of my projects. With a central programmatic config file, I can just go into the loop that sets the properties for all business objects and add a single line of code . . .
However, for some types of dependencies, making the beans partially self describing would be nice. Right now, if a given feature requires a couple of service methods injected, I need to store that information somewhere when rightfully that DI information which is unique to the bean should be in the bean.
So, I'd like to implement beans that are capable of describing their dependencies as an adjunct to the central programmatic config (which I still use for most of my DI metadata). The next question is how best to implement this functionality. Truth be told, I'm not sure.
I could use setter autowiring quite cheaply - init the bean, mix in a method to see what setters it has and to match them up against my bean list, but I don't like setter injection (I prefer mixin injection), so I'm looking for another approach. I could also use getMetadata as Chris described the other week. I think that metadata is the way to go, but for now I'm just going to set a property within variables called variables.MixinObjectNameList. I doubt that's going to conflict with anything else I'm doing and it is going to allow me to add self describing DI to my beans very easily while I play with this and get a feel for it.
This is in 0.62 which will be uploaded within the hour. If you want to ask for objects to be mixin injected, just put the following line of code anywhere in your init() method:
Replacing "UserService,ProductService" with a comma delimited list of bean names (I'm sure I'll replace this with something a little more sophisticated to support bean names that differ from the name I want to bring them in as, but I don't need that for my use case right now (holler if you do and I'll add support). The beans still need to be described within your LightWire programmatic config.
Let me clarify, this is not a full, complete or optimal installation. It doesn't support self describing setters (although I'd be more tempted to add autowiring if I ever wanted to do that) and it doesn't support self describing constructors as that'd be a bit more of a pain to implement (although not too bad in ColdFusion because as we all know the init() method isn't REALLY a constructor, so I can call the bean, then getmetadata, then call the init()).
In short, this is a quick hack to enable a capability and the interface for this will change, but I figured I'd throw it out there as it does no harm and I'd love anyone elses input on how they'd like to see this work and what they think the final syntax should be and why.
I'll let you know when it's up.