ResourceProvider<Session> sessionProvider = new ResourceProvider<Session>() {
public Session get() {
return sessionFactory.openSession();
}
};
ResourceProvider<SessionFactory> sessionFactoryProvider = new ResourceProvider() {
public Object get() {
return sessionFactory;
}
};
final ModelAdapter hibenateAdapter = new HibernateAdapter(sessionFactory);
ResourceProvider<ModelAdapter> modelAdapterProvider = new ResourceProvider<ModelAdapter>()
{
public ModelAdapter get()
{
return hibenateAdapter;
}
};
logger.info("adding binding for: " + hibenateAdapter.getClass());
config.addBinding(ModelAdapter.class, modelAdapterProvider);
logger.info("adding binding for: " + sessionProvider.getClass());
config.addBinding(Session.class, sessionProvider);
logger.info("adding binding for: " + sessionFactoryProvider.getClass());
config.addBinding(SessionFactory.class, sessionFactoryProvider);
logger.info("adding resource provider for: " + sessionProvider.getClass());
config.addResourceProvider("SessionProvider", sessionProvider);
}