vipx / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Independent child Injectors with a shared parent have binding interactions that make them non-useful. #328

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Due to the way parent type blacklisting currently works, all children end
up sharing the same cache of JIT generated objects, regardless of binding
configuration.

This means that I cannot have a parent injector (with no bindings), and
make two independent children of that parent that each bind the same type
in two different ways. 

They will conflict due to the blacklisting and step on each other, making
it impossible.

A case where this is highly desireable is a hierarchy of injectors, where
you have a global injector with overall system state and hooks, and child
injectors that define a few specifics based on the circumstances they are
called in.

A simple use case of this may be: A process that can accept inbound RPC
requests, some of which are 'high priority best effort', and some of which
are 'time critical'

The overall code paths for these may be the same (logic wise), but key
infrastructure implementations may need to be swapped out to provide the
necessary characteristics. Doing this with guide by creating a new child
injector pointing to a module that does that (and only that) is an easy way
of accomplishing this.

Original issue reported on code.google.com by bigwall...@gmail.com on 8 Feb 2009 at 12:47

GoogleCodeExporter commented 9 years ago
I met with the reporter in person to discuss. We're going to attempt to solve 
the other related problems. 

Note that it's fairly reasonable to do this:
  public Module createModuleFromInjector(Injector injector, Key... keys) {
    ...
  }

Original comment by limpbizkit on 26 Apr 2009 at 9:34