You should avoid referencing the injector directly like this since it defeats the purpose of injection (might be okay or not depending of how testable you want that class to be).
Have you considered assisted injection? Create these MyHandler objects with a factory that will be implemented by Guice. More details here: http://beust.com/weblog/2012/08/21/advanced-dependency-injection-with-guice/ -- Cédric On Mon, Nov 12, 2012 at 1:55 PM, Alper Akture <[email protected]>wrote: > I'm using a game server that instantiates objects (Event handlers, etc) > that I would like to inject references into. Since they construct these > instances, is there an approach other than doing something in a default > constructor like this to inject those dependencies? > > public class MyHandler { > MyInectedClass myInjectedObj; > public MyHandler() { > myInjectedObj = > MyInjector.getInstance().getInjector(MyInjectedClass.class); > } > ... > } > > -- > 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/-/jHP4Df5PrHYJ. > 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. > -- 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.
