Hi
Starting up a new project using RF and guice-persist on the server-side to start JPA and provide transaction management.
I have a couple of tests going to inject the EntityManager into the services via the ServiceLocator :
public class ApplicationServiceLocator implements ServiceLocator {
Injector injector = null;
public ApplicationServiceLocator() {
injector = Guice.createInjector(new JpaPersistModule("Test"));
injector.getInstance(ApplicationInitializer.class);
}
@Override
public Object getInstance(Class<?> clazz) {
return injector.getInstance(clazz);
}
}
This makes sure that is EntityManager injected into the service layers :
public class WorkerServiceImpl {
@Inject
private EntityManager em;
@Transactional
public List<Contract> getContracts(User user) {
// I can us EntityManager now !! Injected because created this WorkerServiceImpl was created via injector.getInstance
}
My question : what would be a good approach to inject the EntityManager into an entity class when implementing a service in an entity class ?
What hooks do I have available to do so ?
thx
Koen