I may be misunderstanding something, but what you're talking about sounds a 
lot like the classloader-partitioning that OSGi or the NetBeans module 
system do.

I think hierarchical injectors may actually be unnecessary.  If you use a 
runtime such as NetBeans' one (does not have to be a GUI app) or an OSGi 
container, that takes care of the class visibility issues.

Then you don't actually need hierarchical injectors at all - a "child" 
module can't ask for a type to be injected which it can't refer to at 
runtime at all.  Run your bootstrapping code in the parent classloader and 
use some sort of service lookup pattern to bootstrap all the Guice modules 
registered - something like

        ClassLoader ldr = ...get classloader which can see everything...
        Injector inj = 
Guice.createInjector(ServiceLoader.load(Module.class, ldr));

(this uses JDK 6's ServiceLoader, which works over flat files in 
META-INF/services - NetBeans lookup library contains an annotation + 
processor which will generate them).  I'm probably risking starting a 
religious war by suggesting using ServiceLoader here - but if you want to 
build a self-bootstrapping system that doesn't necessarily know all of it's 
components at compile-time, you need something like that (and bootstrapping 
is a very different problem than injection).

Of course, if two pieces of the system might both want to bind the same 
type, then you may want to start fiddling with private binders (see 
Binder.newPrivateBinder()) and so forth.

But it sounds like the problem you want to solve is isolating components 
from each other in terms of their runtime classpath.  That's a job for 
classloaders, and is a well solved problem in many Java module systems - 
and gives you a stronger guarantee that components can't see - can't even 
load - classes they shouldn't be concerned with, than anything you could do 
with Guice. 

-Tim

-- 
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 http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to