Dependency injection and related techniques

I would like to demonstrate here the most interesting features and styles of use of common Dependency Injection containers. I will use common sample which should also demonstrate the differences among single containers.

Why this page? To be honest I created it to preserve interesting code snippets for later use among other things. I hope you will also find it useful.

The DI containers I will use:
  1. Spring - older but still very popular, mostly because with Spring the developers gets a framework that addresses almost any area in software development. XML for configuration is dead - so we will use Java based configuration solely.
  2. Guice - super elegant and concise DI, but don't expect much more
  3. CDI - standard in JavaEE 6, differs from Spring mostly when it comes to handling scopes
  4. (one for Scala world later)
The main focus in samples is on (might change):
  1. Injection (type-safety, support for generics)
  2. Factories
  3. Parameters / Partial injections
  4. Constants
  5. Scopes
  6. Interceptors
  7. Events
Real World Use cases:
  1. Transactional service
  2. Type-safe configuration 
  3. Caching
  4. Remoting
Source code for running samples can be found at Github:
https://github.com/durdina/samples/tree/master/di-1

0 comments :

Post a Comment