What you're doing seems like a good solution.  You could also approach the
test by using the Elements SPI to get to the private bindings and build a
module out of those.  Something like this in a test:

   // if BlueDatabase is a PrivateModule, there'll only ever be one
PrivateElements in the returned list
   PrivateElements pElements = Elements.getElements(new
BlueDatabase()).iterator().next();

   // Create a module of out the private elements directly
   Module testModule = Elements.getModule(pElements.getElements());

   // Now create an Injector out of that module
   Injector injector =  Guice.createInjector(testModule);

sam

On Fri, Aug 20, 2010 at 3:52 PM, Jason Winnebeck <[email protected]>wrote:

> Is there a way to decide whether or not a module is private at injector
> construction time?
>
> I have two modules that have a lot of overlapping, but different bindings.
> This is the "robot legs" problem mentioned on the FAQ. So in the real app I
> do something like:
>
> Guice.createInjector( new RedDatabase(), new BlueDatabase(), ... );
>
> I need private module here to keep red and blue from conflicting. But in
> integration test (of a single DB) or were I to make a new tool that might
> use just BlueDatabase for example, I might want them to act like normal
> modules so I can get at their full set of bindings. Right now I extend the
> module like so, to make it more like a normal, "public" module:
>
> new BlueDatabase() {
>  protected void configure() {
>    super.configure();
>    expose( Connection.class );
>  }
> }
>
> That way if I make an injector using just BlueDatabase, I can get at its
> connection (unambiguously), since RedDatabase isn't in the picture. Is there
> a cleaner way to do this?
>
> I can imagine the opposite could happen too, where someone else writes
> RedDatabase and BlueDatabase independently as AbstractModule and I want to
> combine them in my project. I don't think child injectors would help here. I
> don't have this problem but I am curious what I could do if I had to make a
> module "private" when it was "public".
>
> Thanks,
> Jason
>
> --
> 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]<google-guice%[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