I was wondering how the injector is typically used. I understand that it's used mainly at start-up time, but how would you use it at run-time to create an object of certain implementation?
For example, I have an interface User with implementation of UserA, UserB and UserC. My idea of using Guice at run-time is to wrap it in a Singleton class so that I can get retrieve it rather than creating a new injector every time I want to create an instance of User object.
//Create in singleton wrapper class
Injector injector = Guice.createInjector(new SecurityModule());
//Retrieve and use at run-time (Manager is the singleton wrapper class)
Injector injector = Manager.getInstance().getInjector();
User user = injector.getInstance(User.class);
Is this how it's typically done? Basically, I want to make sure that I centralize all configuration so that there is less error (e.g. using the wrong module). It's also easier to manage so if I decided to use a different configuration module, I can just change it in a class, rather than in every Java class that is using it.
Thanks, Jack