Re: Comment on AvoidConditionalLogicInModules in google-guice

34 views
Skip to first unread message

google...@googlecode.com

unread,
Aug 5, 2012, 12:18:42 PM8/5/12
to google-g...@googlegroups.com
Comment by c...@thebrighttag.com:

+1 for the two-module example. Seems like you'd just be creating a new
module which conditionally install()s one of the implementation modules
(RemoteFooModule, InMemoryFooModule). Not sure how this is any different
than that outlined above.

For more information:
http://code.google.com/p/google-guice/wiki/AvoidConditionalLogicInModules

google...@googlecode.com

unread,
Sep 6, 2012, 8:13:26 AM9/6/12
to google-g...@googlegroups.com
Comment by gervai...@gmail.com:

+1 for the two-module example too. How can we switch between the two
without conditions ?

google...@googlecode.com

unread,
Dec 5, 2012, 12:21:15 AM12/5/12
to google-g...@googlegroups.com
Comment by apismen...@gmail.com:

+1

google...@googlecode.com

unread,
Dec 5, 2012, 12:24:09 AM12/5/12
to google-g...@googlegroups.com
Comment by apismen...@gmail.com:

Also I would like to see a real example of using Instance Binding for
configuration and switching between configurations (DEV, TEST, PROD etc)

google...@googlecode.com

unread,
Dec 12, 2012, 12:06:32 PM12/12/12
to google-g...@googlegroups.com
Comment by l...@comoyo.com:

+1 for the example ...

google...@googlecode.com

unread,
May 16, 2013, 12:29:28 PM5/16/13
to google-g...@googlegroups.com
Comment by isaac.mo...@gmail.com:

+1 To this almost three year old petition of an example

For more information:
https://code.google.com/p/google-guice/wiki/AvoidConditionalLogicInModules

google...@googlecode.com

unread,
May 17, 2013, 6:33:05 AM5/17/13
to google-g...@googlegroups.com
Comment by mccu...@gmail.com:

It would go something like this:
{{{
public class RemoteFooModule extends AbstractModule {
private final String fooServer;

public RemoteFooModule(String fooServer) {
this.fooServer = fooServer;
}

@Override protected void configure() {

bind(String.class).annotatedWith(named("fooServer")).toInstance(fooServer);
bind(FooService.class).to(RemoteFooService.class);
}
}
}}}

{{{
public class InMemoryFooModule extends AbstractModule {
@Override protected void configure() {
bind(FooService.class).to(InMemoryFooService.class);
}
}
}}}

Then in your bootstrap code that selects the application modules and calls
{{{Guice.createInjector(modules);}}} you would choose whether to add the
RemoteFooModule or InMemoryFooService depending on the application's
properties/arguments/environment.

google...@googlecode.com

unread,
Sep 27, 2013, 3:42:24 PM9/27/13
to google-g...@googlegroups.com
Comment by gtass...@gmail.com:

Wouldn't this require all the dependencies for both modules to be present
on the bootstrap application's classpath? Or else, to support a new module
and set of bound implementation classes, one would have to update and
recompile the bootstrap application code.
Reply all
Reply to author
Forward
0 new messages