I have a situation where I initialize some of my classes, some of the fields that I need to enter (e.g. links to factories, etc.), while some others are dynamic and are created at runtime (e.g. user names etc.). How can I build such objects using the GUICE infrastructure? Just commenting on the fields that I need to enter as @Inject does not work, as they don't seem to be set up when creating an object using the constructor. For instance:
class C { @Inject private FactoryClass toBeInjected; private ConfigurationField passedIn; public C(ConfigurationField passedIn) { this.passedIn = passedIn; } }
If my understanding is correct (and I could be wrong), the fact that I create a new instance of C through new , and not through Guice, means that the injection will not happen. I need to pass these parameters in the constructor, but also want some fields to be entered - so how can I solve this problem?
source share