Interface BeanContextClient
-
- All Known Implementing Classes:
CommandActionTask
public interface BeanContextClient
Definition of an interface to be implemented by beans that need a reference to the current
BeanContext
.Sometimes beans defined using the dependency injection framework also want to use the framework for accessing other beans through a
BeanContext
. This is often the case if the dependencies of a bean are not fully known at design time, but are determined based on certain criteria at runtime. In such cases a reference to the currentBeanContext
must somehow be passed to the affected beans.This interface marks a bean as a client of a
BeanContext
. It defines a single method, through which theBeanContext
can be passed to the object. The dependency injection framework checks for each bean that is newly created whether it implements this interface. If this is the case, thesetBeanContext()
method is automatically called. Thus theBeanContext
becomes known to the bean and can be used later for accessing other dependencies. No additional configuration steps are required to use this feature. Every bean implementing this interface is automatically initialized with the currentBeanContext
.One big advantage of dependency injection is that it tends to be non-invasive: the beans managed by the framework need not implement specific interfaces or extend certain base classes; the framework handles their creation and initialization transparently. By implementing this interface beans define a direct dependency to this framework, which makes it harder to use them in a different context. So before making use of this feature possible alternatives should be evaluated, or at least the developer should be aware that a tight coupling to this specific dependency injection framework is introduced.
- Version:
- $Id: BeanContextClient.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
setBeanContext(BeanContext context)
Passes the currentBeanContext
to this object.
-
-
-
Method Detail
-
setBeanContext
void setBeanContext(BeanContext context)
Passes the currentBeanContext
to this object. This method is invoked by the framework after initialization of this object is complete. At this time all dependencies to other beans have been resolved, butBeanCreationListener
s registered at the context have not yet been invoked. An implementation will typical store the passed inBeanContext
for later use.- Parameters:
context
- the currentBeanContext
-
-