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 current BeanContext
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 the BeanContext
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, the
setBeanContext()
method is automatically called. Thus the
BeanContext
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 current BeanContext
.
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.
Modifier and Type | Method and Description |
---|---|
void |
setBeanContext(BeanContext context)
Passes the current
BeanContext to this object. |
void setBeanContext(BeanContext context)
BeanContext
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, but
BeanCreationListener
s registered at the context have not yet been
invoked. An implementation will typical store the passed in BeanContext
for later use.context
- the current BeanContext
Copyright © 2016 The JGUIraffe Team. All rights reserved.