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 google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
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);}...}
Thanks Cedric, I totally agree, I don't like using the injector directly. I wasn't aware of assisted injection, could be very useful. However, for many of my classes I have problems with, I give the framework the class name (in an init method that they call), and they do the instantiation. Something like this:public void initHandlers() {
addEventHandler(SFSEventType.USER_LOGIN, UserLoginEventHandler.class);
...
}
And I would need to inject stuff into the UserLoginEventHandler.class. So I don't think assisted inject can help here, can it?