Friday, June 11, 2010

Implementing your own Dependency Injection, Part 2

In my previous post "Implementing Your own DI", I discussed how to implement a simple dependency injection using Java Annotations and Reflection API. In this post, I will discuss about adding some extra features to the previous implementation.

The new features included are:
  • Constructor level injection.
  • Injecting methods with multi-parameters.
  • Resolve dependencies by specifying an id, if not specified use the member's name (field's name or setter method's name) instead, or by class type.
  • Dependencies can be marked as optional.
  • Adding foreign objects. Objects that are not created by this implementation but are dependencies of classes created and wired by this implementation.