hello guys!

I am developing a project JSE with Hibernate, JPA and Guice to inject 
dependencies and part of persistence.

But I think there's something wrong with my architecture ... I have the 
following scenario:

I have a bean that maps the database and has the attributes of the person 
(for example) to access the data of this person have a DAO composed by 
interface where I keep the access methods and the implementation of this 
interface where actually writes that these methods will do. All DAOs extend 
an abstract DAO that has entitymanager.

To use DAO created a controller that receives via @inject the DAO 
implementation class to be controlled.

however every time you need to use the controller have to get a new 
injector instantiating and initializing the PersistentService

eg

when I want to use the controller:

*PersonController controller = PersonController.getInstance();*

the getInstance() method run:

*Injector injector = Guice.createInjector(new 
JpaPersistModule("MyBudgetPU"));*
*        *
*injector.getInstance(PersistenceInitializer.class);*
*        *
*return injector.getInstance(PersonController.class);*

where the line "injector.getInstance (PersistenceInitializer.class)" I 
initialize the PersistentService with the class:

*public class PersistenceInitializer {*
*
*
*        @Inject*
*        public PersistenceInitializer(PersistService persistService) {*
*            persistService.start();*
*        }*
*    }*

Finally, my question is if you really need to be doing this every time you 
have to use a controller or is there a way I can make just one time and all 
the controller's having their members injected, or at least maintain the 
service of persistence started without keep starting him every time.

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-guice/-/FrcgcsXP0qMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to