Package org.apache.wicket.guice
Class GuiceComponentInjector
- java.lang.Object
-
- org.apache.wicket.injection.Injector
-
- org.apache.wicket.guice.GuiceComponentInjector
-
- All Implemented Interfaces:
IComponentInstantiationListener
,IBehaviorInstantiationListener
public class GuiceComponentInjector extends Injector implements IComponentInstantiationListener, IBehaviorInstantiationListener
Injects field members of components and behaviors using Guice.Add this to your application in its
Application.init()
method like so:getComponentInstantiationListeners().add(new GuiceComponentInjector(this));
There are different constructors for this object depending on how you want to wire things. See the javadoc for the constructors for more information.
Only Wicket
Component
s andBehavior
s are automatically injected, other classes such asSession
,Model
, and any other POJO can be injected by callingInjector.get().inject(this)
in their constructor.- Author:
- Alastair Maw
-
-
Constructor Summary
Constructors Constructor Description GuiceComponentInjector(Application app)
Creates a new Wicket GuiceComponentInjector instance.GuiceComponentInjector(Application app, com.google.inject.Injector injector)
ConstructorGuiceComponentInjector(Application app, com.google.inject.Injector injector, boolean wrapInProxies)
Creates a new Wicket GuiceComponentInjector instance, using the provided GuiceInjector
instance.GuiceComponentInjector(Application app, com.google.inject.Module... modules)
Creates a new Wicket GuiceComponentInjector instance, using the supplied GuiceModule
instances to create a new GuiceInjector
instance internally.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
inject(Object object)
Injects the specified object.void
onInstantiation(Behavior behavior)
Called when a behavior instance is createdvoid
onInstantiation(Component component)
Called for every component that is instantiated.
-
-
-
Constructor Detail
-
GuiceComponentInjector
public GuiceComponentInjector(Application app)
Creates a new Wicket GuiceComponentInjector instance.Internally this will create a new Guice
Injector
instance, with noModule
instances. This is only useful if your beans have appropriateImplementedBy
annotations on them so that they can be automatically picked up with no extra configuration code.- Parameters:
app
-
-
GuiceComponentInjector
public GuiceComponentInjector(Application app, com.google.inject.Module... modules)
Creates a new Wicket GuiceComponentInjector instance, using the supplied GuiceModule
instances to create a new GuiceInjector
instance internally.- Parameters:
app
-modules
-
-
GuiceComponentInjector
public GuiceComponentInjector(Application app, com.google.inject.Injector injector)
Constructor- Parameters:
app
-injector
-
-
GuiceComponentInjector
public GuiceComponentInjector(Application app, com.google.inject.Injector injector, boolean wrapInProxies)
Creates a new Wicket GuiceComponentInjector instance, using the provided GuiceInjector
instance.- Parameters:
app
-injector
-wrapInProxies
- whether or not wicket should wrap dependencies with specialized proxies that can be safely serialized. in most cases this should be set to true.
-
-
Method Detail
-
inject
public void inject(Object object)
Description copied from class:Injector
Injects the specified object. This method is usually implemented by delegating toInjector.inject(Object, IFieldValueFactory)
with someIFieldValueFactory
- Specified by:
inject
in classInjector
- See Also:
Injector.inject(Object, IFieldValueFactory)
-
onInstantiation
public void onInstantiation(Component component)
Description copied from interface:IComponentInstantiationListener
Called for every component that is instantiated. This method is called during construction, so do not depend on the construction being completed yet. The id is guaranteed to be set before this call.- Specified by:
onInstantiation
in interfaceIComponentInstantiationListener
- Parameters:
component
- the component that is being instantiated.
-
onInstantiation
public void onInstantiation(Behavior behavior)
Description copied from interface:IBehaviorInstantiationListener
Called when a behavior instance is created- Specified by:
onInstantiation
in interfaceIBehaviorInstantiationListener
-
-