Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support chaining injectors / parent injectors #45

Closed
gissuebot opened this issue Jul 7, 2014 · 19 comments
Closed

Support chaining injectors / parent injectors #45

gissuebot opened this issue Jul 7, 2014 · 19 comments

Comments

@gissuebot
Copy link

From crazyboblee on February 28, 2007 14:09:33

For example, I could pass a Container to a Binder and the resulting
Container would include all the bindings from the original Container. This
can be used the implement layering (i.e. view layer container includes the
application layer container) as well as initialization stages.

Original issue: http://code.google.com/p/google-guice/issues/detail?id=45

@gissuebot
Copy link
Author

From kevinb9n on February 28, 2007 11:14:44

What about including any already-initialized singletons from the original container?
 This could possibly allow us to solve our functional testing "speed vs. safety"
problems, as we can actually create and launch a whole new server for every test
while reusing only those damned expensive singletons.

@gissuebot
Copy link
Author

From crazyboblee on February 28, 2007 12:04:24

We would pretty much have to do that. I also think sharing the instance is the least
surprising behavior.

@gissuebot
Copy link
Author

From crazyboblee on February 28, 2007 14:46:31

Container has been renamed Injector.

I think being able to pass an Injector to a Binder is pretty safe and has a lot of
potential uses.

Labels: 1.0RC3

@gissuebot
Copy link
Author

From crazyboblee on February 28, 2007 14:48:44

Container has been renamed Injector.

I think being able to pass an Injector to a Binder is pretty safe and has a lot of
potential uses.

@gissuebot
Copy link
Author

From crazyboblee on March 02, 2007 13:20:45

Deferring until I figure out how we want to do this.

Should the containers share implicit bindings, too? i.e. consider an implicit
singleton. If the child container delegates to the parent container for implicit
bindings, how will the parent get access to the child's explicit bindings?

We need to copy scope bindings, too.

How will method interception work? I suppose we need to expose and copy the method
aspects. If we share implicit bindings, then interceptors applied for the child won't
apply...

I think keeping implicit bindings separate and only copying explicit bindings is the
way to go.

Labels: -1.0RC3

@gissuebot
Copy link
Author

From crazyboblee on March 13, 2007 15:31:34

(No comment was entered for this change.)

Summary: Support chaining injectors.

@gissuebot
Copy link
Author

From kevinb9n on June 03, 2007 11:01:39

People who want this feature, please-pretty-please add your use cases here.  thanks.

@gissuebot
Copy link
Author

From crazyboblee on June 03, 2007 11:07:32

I don't think we should implement this. You can always enforce layering when compiling.

@gissuebot
Copy link
Author

From kevinb9n on June 03, 2007 11:38:39

I've gotten the general sense that there are other reasons besides layering why
people want this.  We'll see.

@gissuebot
Copy link
Author

From oliver.buchtala on February 16, 2008 16:43:34

Hi,

I don't know the current state of this issue. But I have 'working' prototype.

I very much like the idea of injector chains.
First my usecase: (robot-leg)
I have many kind of algorithms that have similar 'signatures', e.g., working on sets
of data-instances(e.g. Iterable<Data>). Now, I have to use several of them, each
working on a different data-set instance - or a certain subset of the whole data-set.
Furthermore, i like to have the same algorithm working on different parts of my data
set (or different instances).
I think, this is very much a robot-leg-problem.

I tried to find out if Scopes are my solution - but, as I think, I have to bind the
my algorithm class to the scope. So, not several instances in several scopes. I also
think Scopes more as of a a living context. Not a visbility context - what I need.

I worked out a simple Prototype of an hierarchical binder impl that does what I
wish. It uses Providers living in different Injectors (e.g., child/parent injector)
and binds them in the other as concrete providers.
Additionally I added some kind of automatic Binding inheritance (i.e., global
bindings).
You find the source with a demonstrative example in the attached file.

Current problem: eagerSingletons - may lead (very likely) to calls on the bridging
providers before the bridged injector was created. (...I don't like asEagerSingleton
at all).

What do you think?

Greetz,
Oliver

Binary attachments: GuiceWithHierarchicalModules.zip

@gissuebot
Copy link
Author

From limpbizkit on May 30, 2008 00:26:36

Dan Halem has implemented a prototype of this in Guice svn. But I'd still like to make a thorough examination of
all of this code and its consequences. I'm particularly anxious about this for 2.0.

@gissuebot
Copy link
Author

From limpbizkit on June 06, 2008 09:24:46

(No comment was entered for this change.)

Summary: Support chaining injectors / parent injectors
Labels: Milestone-Release2.0

@gissuebot
Copy link
Author

From limpbizkit on June 17, 2008 11:32:40

There's a bug in the current implementation where deep hierarchies are not honoured: http://groups.google.com/group/google-guice/browse_frm/thread/4689199d93d76ecb

@gissuebot
Copy link
Author

From medotin on July 11, 2008 10:10:24

@13
Have not tested for implications, but a workaround seems to be changing
Scopes.NO_SCOPE to binding.getScope() on this line: http://fisheye2.atlassian.com/browse/google-guice/trunk/src/com/google/inject/InjectorImpl.java?r=555#l254

@gissuebot
Copy link
Author

@gissuebot
Copy link
Author

From sven.linstaedt on September 10, 2008 01:55:13

There is another bug: Constant bindings are not inherited from the parent injector.

So while retrieving an object which depends on constant bindings from the parent
injector works, the same object can not be retrieved from a child injector of this
parent one. Guice states that the constant dependency is not bound.

@gissuebot
Copy link
Author

From limpbizkit on October 14, 2008 16:43:45

I've rewritten parent injectors from scratch. From the Injector.java API:

  /**
   * Returns a new injector that inherits all state from this injector. All
   * bindings, scopes, interceptors and type converters are inherited -- they
   * are visible to the child injector. Elements of the child injector are not
   * visible to its parent.
   *
   * <p>Just-in-time bindings created for child injectors will be created in an
   * ancestor injector whenever possible. This allows for scoped instances to be
   * shared between injectors. Use explicit bindings to prevent bindings from
   * being shared with the parent injector.
   *
   * <p>No key may be bound by both an injector and one of its ancestors. This
   * includes just-in-time bindings. The lone exception is the key for {@code
   * Injector.class}, which is bound by each injector to itself.
   */
  Injector createChildInjector(Iterable<? extends Module> modules); https://code.google.com/p/google-guice/source/detail?r=629

Status: Started
Owner: limpbizkit

@gissuebot
Copy link
Author

From sven.linstaedt on October 15, 2008 06:20:35

Have a look at related discussion: http://groups.google.com/group/google-guice-dev/browse_thread/thread/c097874268bf9209?hl=en

@gissuebot
Copy link
Author

From limpbizkit on November 12, 2008 17:18:57

Implemented and now threadsafe. Hooray!

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant