Are there any IoC containers out there that have an easy way to configure without using XML. Specifically, a configuration mechanism that lends itself well to refactoring?
I’m a big fan of EasyMock and the way mocks are configured is by using record-and-playback approach. That is, first you create your mock and call methods on it while it is record mode. Those method calls become the expectations on the mock. Then you call mock.playback() and now the same object is ready to be used as a mock, expecting the same calls it just recorded.
So why not do this for an IoC container? Consider the following code used to configure your IoC-managed beans:
Foo foo = ContainerSetup.configure(Foo.class); Bar bar = ContainerSetup.configure(Bar.class); foo.setBar(bar); ContainerSetup.done();
Now when I refactor Foo or Bar, my configuration is also refactored. I’m sure there are other ways something like this can be done. Thoughts?
on Jan 31st, 2006 at 9:43 pm
Alas, not yet, but I have some ideas for HiveMind 1.2 that will provide an alternative, code (code + naming conventions + annotations) approach to instantiatiating and initializing services.
on Jan 31st, 2006 at 9:44 pm
Also, Rod Johnson showed my some experimental Spring code back at JavaOne 2005 that was very similar to what you describe. The best ideas are rarely unique!
on Feb 1st, 2006 at 5:39 pm
Seam provides a more advanced form of dependency injection without using XML configuration. Personally, I don’t think it’s the XML that makes spring so bulky and (dare I say) heavy. I think it’s the micromanagement and needing to sit there and configure every single minute detail. The configuration by exception methodology of EJB3 definitely makes a lot more sense and is much simpler.