Hi,

I need to create a new instance of the Plugin each time i call
"createPlugin" on my PluginFactory.

Multibinder<Plugin> plugins =
Multibinder.<Plugin>newSetBinder(binder(), Plugin.class);
plugins.addBinding().to(A.class);
plugins.addBinding().to(B.class);
...

bind(PluginFactory.class).to(PluginFactoryImpl.class);

Where my PluginFactoryImpl is:

@Inject Set<Plugin> plugins;

public Plugin createPlugin(String name) {
    ... goes through the 'plugins' and return the one which match the
name.

The problem here is of course that the plugins-set is created on
injection-time, so next time createPlugin is called with the same name-
argument I will get a reference to the same instance as before. I need
a "new" instance.

I use my factory like this (which gives me same old instance all the
time):

public class MyApp {
    @Inject PluginFactory factory;

    public Plugin execute(String name) {
        factory.createPlugin(name).execute();
    }
}

How would one go about doing something like that?

Cheers,
Jonas

-- 
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.

Reply via email to