java - How to bind one implementation to a few interfaces with Google Guice? -


i need bind 1 class implementation of 2 interfaces. , should binded in singleton scope.

what i've done:

bind(firstsettings.class).     to(defaultsettings.class).     in(singleton.class); bind(secondsettings.class).     to(defaultsettings.class).     in(singleton.class); 

but, obviously, leads creation of 2 different instances, because binded different keys.

my question how can that?

guice's wiki has a documentation use case.

basically, should do:

// declare provider of defaultsettings singleton bind(defaultsettings.class).in(singleton.class);  // bind providers of interfaces firstsettings , secondsettings // provider of defaultsettings (which singleton defined above) bind(firstsettings.class).to(defaultsettings.class); bind(secondsettings.class).to(defaultsettings.class); 

there no need specify additional classes: think in terms of providers , answer comes rather naturally.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -