Looks fine to me. Of course, since Guice.createInjector can be passed any
number of Modules, you don't need to use one Module that installs the
others unless you want to. For instance, rather than passing the
MpsServiceModule to the MpsModule constructor and then installing it, you
could just pass it to createInjector alongside the MpsModule.  If you
wanted to ensure in MpsModule that some binding(s) had been done elsewhere,
you could use, say, requireBinding(MpsService.class). Up to you.

-- 
Colin


On Mon, Feb 13, 2012 at 1:41 AM, egolan <[email protected]> wrote:

> anyone?
>
> On Feb 10, 4:34 pm, egolan <[email protected]> wrote:
> > Hi,
> > I would like to consult whether the way I constructed my modules is
> > the preferred way.
> >
> > I created a module for each part of the application (a Guice Abstract
> > module for some logic module in the application).
> > I have a main module that in its configure method, it uses
> > install(...) method.
> > The main class calls this module and the Guice.getInjector() and run
> > what it need to run.
> >
> > One of the sub module is not created in the main module, but instead
> > the main creates it and call the main module with it.
> > I did it to allow me to do an end2end test with the main module, but
> > with a different sub module.
> >
> > Main module:
> > public MpsModule(Properties properties, MpsServiceModule
> > moduleForMpsService) {
> >         this.properties = properties;
> >         this.moduleForMpsService = moduleForMpsService;
> >     }
> >
> >     @Override
> >     protected void configure() {
> >         Names.bindProperties(binder(), properties);
> >         convertToTypes(dateMatcher(), dateConverter());
> >         install(new MpsBizModule());
> >         install(new MpsLogicModule());
> >         install(moduleForMpsService);
> >         install(new
> > ConfigurationModule(MpsConfigurationName.MpsLastProcessingTime.name()));
> >     }
> >
> > Here's the sub module that I have different implementation for using
> > different service:
> > (MpsServiceModule just extends Module)
> > public class MpsServiceModuleImpl extends AbstractModule implements
> > MpsServiceModule {
> >     public MpsServiceModuleImpl() {
> >         System.out.println("----------------- MpsServiceModuleImpl
> > -----------------");
> >     }
> >
> >     @Override
> >     protected void configure() {
> >
> > ThrowingProviderBinder.create(binder()).bind(MpsServiceProvider.class,
> > IProductMatchService.class).to(
> >                 MpsServiceProviderImpl.class);
> >     }
> >
> > }
> >
> > Any comments?
> >
> > Thanks,
> >
> > Eyal
>
> --
> 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.
>
>

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