indiWiz.com

Subhash's Tech Log

Archive for the ‘DI’ tag

Standardized DI Annotations for Java

with one comment

At last, at last, some action is going on in this direction!

Written by Subhash Chandran

May 6th, 2009 at 10:11 am

Posted in news

Tagged with ,

Implementing a DI Framework for WizTools.org RESTClient

with 2 comments

I wanted very basic DI functionality for RESTClient. Just wanted a mock implementation to execute when doing a mvn test, and real implementation when executed otherwise. So the functionality was simple. My immediate requirement did not require constructor injection or setter injection. And all the beans instantiated had to be singletons. No other fancy requirement. So for this limited functionality, I was able to design a small framework in two classes: DIFramework.java and DIException.java. For mapping the implementation to the interface, it is managed using a simple property file with content:

org.wiztools.restclient.IGlobalOptions = org.wiztools.restclient.GlobalOptions

The mock implementation in the test execution would be:

org.wiztools.restclient.IGlobalOptions = org.wiztools.restclient.MockGlobalOptions

org.wiztools.restclient.IGlobalOptions is the interface, and org.wiztools.restclient.GlobalOptions and org.wiztools.restclient.MockGlobalOptions are the implementation. To get instance of implementation bean:

IGlobalOptions obj = DIFramework.getInstance(IGlobalOptions.class);

This would return two different beans in different execution environments based on the property control.

Written by Subhash Chandran

December 15th, 2008 at 10:04 pm

Posted in Java,OpenSource

Tagged with , , ,

DI: Annotation or XML Configuration

with one comment

Recently I have been looking at couple of DI containers in Java. These are: Google Guice and Spring Framework. I did not like Guice in the first look itself. It involved annotating my beans with Guice specific annotations. I felt this was defeating the purpose of POJO. XML configuration using Spring was more natural for me.

Written by Subhash Chandran

December 15th, 2008 at 9:11 pm

Posted in Java

Tagged with , ,