I have a singleton service object which looks something like this.. 

@Singleton
public class DAO {

    private ElasticsearchTemplate template;

    public DAO(Configuration config) {
        // some initialisation code
    }
}

and I made guice aware of this in my Module like this...

public class DAOModule extends AbstractModule {

    @Override
    protected void configure() {
        bind(DAO.class).asEagerSingleton();
    }
}

The above setup works great, and without any problems. 

Now, I have another module which looks like this..

public class EmailModule extends AbstractModule {

    public EmailModule(Environment env, Configuration config) {
        // init code
    }

    @Override
    protected void configure() {
         Mail client = new Mail() // I want to pass the dao service to this
         
         bind(Mail.class).toInstance(client);
    }
}


If you look at EmailModule, part of the issue is I can't change the 
constructor to receive additional parameter since PlayFramework by default 
only seems to pass those. 

If I try something like 

@Provides
DAO getDAO(Injector injector) {

    return injector.getInstance(DAO.class);
}

I get a "A binding to DAO was already configured at DAOModule.getDAO"

My question is, how do I get an instance of DAO into EmailModule?

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/f3dc4b95-bb13-4b10-adfe-dfbb6bdee7ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to