There are cases, the object is not singleton, such as VolumeObject, but it 
needs to access DAO, then either we need to pass the DAOs in the VolumeObject's 
constructor, or through ComponentContext.inject(), or using AspectJ's 
@Configurable(http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/aop.html#aop-atconfigurable)
BTW, why  ComponentContext.inject() breaks IoC and DI patterns? Per my 
understanding, ComponentContext.inject() just tells IoC container to take care 
of the object creation, as the object created by "new" operator won't be 
injected by IoC container by default.

> -----Original Message-----
> From: Darren Shepherd [mailto:darren.s.sheph...@gmail.com]
> Sent: Wednesday, August 28, 2013 11:56 AM
> To: dev@cloudstack.apache.org
> Subject: ComponentContext.inject() usage in storage framework
> 
> The new storage framework uses ComponentContext.inject() extensively.
> Why is that?  ComponentContext.inject() should really never be used.  It
> breaks IoC and DI patterns.
> 
> For example, in configure() of SwiftImageStoreProviderImpl it does
> 
> lifeCycle = ComponentContext.inject(SwiftImageStoreLifeCycleImpl.class);
> driver = ComponentContext.inject(SwiftImageStoreDriverImpl.class);
> 
> Why not just do the below? It keeps the IoC/DI pattern and should do the
> same thing.
> 
> @Inject
> SwiftImageStoreLifeCycleImpl lifeCycle;
> @Inject
> SwiftImageStoreDriverImpl driver;
> 
> 
> Darren

Reply via email to