Wicket RAD and wicket-guice on Wicket 1.4
Hi,
As the topic of Wicket-RAD and Guice (superb lightweight dependency injection with type safety and annotations) came up on Twitter I will continue the discussion here...
Regarding using Wicket-RAD with wicket-guice on Wicket 1.4, there is really not much Wicket-RAD specific to say. I have been using this combination for a while and the only requirement is that Wicket-RAD is compiled with Wicket 1.4. Otherwise you will get runtime error since some Wicket base class has changed from 1.3.
Below is the relevant part from the application init() method from one of my applications. I am also using Guice and Wicket with Warp-Persist. An annotation based persistence framework combining Guice and Hibernate annotations with some cool features (hint DynamicFinders... ++ ).
@Override
protected void init()
{
log.trace("entering Application.init()...");
/*
* Setting up Warp persistence w/ Hibernate
*/
injector = Guice.createInjector(
PersistenceService
.usingHibernate()
.across(UnitOfWork.REQUEST)
.transactedWith(TransactionStrategy.LOCAL)
.addAccessor(DataAccessorService.class)
.buildModule(),
new GuiceModule());
// enabling Guice for Wicket applicatation
addComponentInstantiationListener(new GuiceComponentInjector(this, injector));
PersistenceService persistenceService = injector.getInstance(PersistenceService.class);
persistenceService.start();
injector.injectMembers(this);
What is happening is that You first create an injector by passing the "createInjector" method of Guice two Guice modules. The first module is the a Warp-Persist persistence module, the second module is our application's Guice configuration class.
Second we add a component instatiation listener to our application. This makes sure that Guice gets a chance to inject objects when our wicket objects are instantiated by the application.
Third the Warp-Persist service is started.
Last I tell the injector to inject members into the application class itself. I believe this is only required if you need to inject something into the application object itself.
Regards,
Oyvind