For a standalone application (running as a daemon in the background) I
trying to find out if Guice would be a correct solution to handle
Dependency Injection. Most DI solutions are used in webapplications and I
cant find the proper way to use Guice in a standalone application. I
basically have two questions:
1. How would one bootstrap the application? I could see something like this
in the main() method, but I wonder if this is the best solution?
public static void main(String[] arges) {
Injector injector = Guice.createInjector(new TestModule());
WorkerService service = injector.getInstance(WorkerService.class);
service.start();
}
2. How do I properly configure all my bindings? By skimming through some
documentation and testing out a few things, I have this to bind my
testmodule, but I doubt this is the correct solution when you have allot of
bindings. Can this be done (semi) automatically? Or do I have to
create/configure everything I want to inject somewhere? (that will result
in a long list of bind(...).to(...) in allot of modules).
public class TestModule extends AbstractModule{
@Override
protected void configure() {
bind(TestService.class).to(TestServiceImpl.class);
bind(WorkerService.class).to(WorkerServiceImpl.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/-/RcoHYvLsOG8J.
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.