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 on http://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 -~----------~----~----~----~------~----~------~--~---
