This 'smell' is exactly what I had noticed and prompted me to post to see if there was something better ;-)
I will take a look at Guts now - thanks for the tip. But on the point of getting a Startup class... My UI layer will be quite seperate from the guice layer (as im coding for both a swing ui and javafx ui) So i will have different parts of the applciation that need to call into the guice layer - I dont see a way to avoid having to boostrap and hold a reference in somethign like a singleton so that different parts of the UI can make the following calls: // done somewhere at app startup / entry point ClientCore.INSTANCE.bootstrap(); // later somewhere in the UI: ClientService clientService = ClientCore.INSTANCE.getInjector ().getInstance(ClientService.class); Guice has done all the nice DI for me... and now I can use the ClientService in the UI layer for data access/operation etc.. On Nov 2, 3:10 pm, Jean-Francois Poilpret <[email protected]> wrote: > aloleary wrote: > > Hello, > > New to Guice - coming from Spring.. > > > I am working on developing a lightweight java layer based on google- > > guice and EventBus to give me some very lightweight decoupled modules. > > This 'layer' will be used by a Swing and eventually JavaFX UI. > > Except for the JavaFX UI, what you want to do looks like what Guts-GUI > project aims to do (and has already started to do). > You may want to take a look at it onhttp://kenai.com/projects/guts/ > Guts project also includes an event bus that is 100% based on Guice and > takes large advantage of Guice type-safety.> I am wondering what is 'best > practice' or what is typcially done when > > dealing with the Injector... > > > In Spring I can get the application context at any point through a > > singleton - it doesnt keep bootstrapping.. > > > In Guice I do the following: > > > Injector injector = Guice.createInjector(new TestModule()); > > Generally you don't need to hold that injector somehow. Immediately > after creating the injector, you should use it to get some kind of > Startup class instance that is injected by Guice and which dependencies > shall also be injected by Guice. Generally speaking, holding a reference > to Inejctor (or worse, passing around such a reference) is a design smell. > > Cheers > > Jean-Francois > > > This seems like something I need to do once... > > > Therefore is it a case of doing this on app startup and maintaining a > > reference to the Injector myself ? > > > There is tonnes of examples of setting up DI in Guice but I guess I'm > > looking at what best practices are for the external code > > > Thanks > > -A- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "google-guice" group. 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 -~----------~----~----~----~------~----~------~--~---
