aloleary wrote: > 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.. > > Why can't you inject ClientService in your UI? You could bind your UI classes in the Injector you create by using 2 different Modules, one for Swing, one for JavaFX, and perform the selection (one or the other) at Injector creation time. You could also define bindings for all common components in a third module (doesn't need to change depending on UI layer) that you pass also to the list of Modules in Guice.createInjector().
Using singletons when using Guice (be it for holding the Injector or anything else) is also a design smell that can definitely be avoided when using Guice. The only point for your UI is that your classes will have to use @Inject to get the ClientService or whatever else they want. Cheers Jean-Francois --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
