[picocontainer-scm] [5566] java/2.x/trunk/pico/container/src/java/org/picocontainer: PICO-368 fixed by Johan Hoogenboezem

paul-yCVjj/[email protected]
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <[email protected]>
Revision 5566
Author paul
Date 2009-12-31 09:36:13 -0600 (Thu, 31 Dec 2009)

Log Message

PICO-368 fixed by Johan Hoogenboezem

Modified Paths

- java/2.x/trunk/pico/container/src/java/org/picocontainer/DefaultPicoContainer.java

Added Paths

- java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/IntoTypeTestCase.java

Diff

Modified: java/2.x/trunk/pico/container/src/java/org/picocontainer/DefaultPicoContainer.java (5565 => 5566)

--- java/2.x/trunk/pico/container/src/java/org/picocontainer/DefaultPicoContainer.java 2009-12-01 03:15:03 UTC (rev 5565)
+++ java/2.x/trunk/pico/container/src/java/org/picocontainer/DefaultPicoContainer.java 2009-12-31 15:36:13 UTC (rev 5566)
@@ -684,8 +684,7 @@
intoThreadLocal = new IntoThreadLocal();
}
}
- intoThreadLocal.set(new InjectInto(componentAdapter.getComponentImplementation(), componentAdapter.getComponentKey()));
- instance = componentAdapter.getComponentInstance(this, ComponentAdapter.NOTHING.class);
+ instance = componentAdapter.getComponentInstance(this, intoThreadLocal.get());
}
} catch (AbstractInjector.CyclicDependencyException e) {
if (parent != null) {

Added: java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/IntoTypeTestCase.java (0 => 5566)

--- java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/IntoTypeTestCase.java (rev 0)
+++ java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/IntoTypeTestCase.java 2009-12-31 15:36:13 UTC (rev 5566)
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved. *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file. *
+ * *
+ * Original code by Johan Hoogenboezem (thanks Johan) *
+ *****************************************************************************/
+package org.picocontainer.injectors;
+
+import static org.junit.Assert.*;
+
+import org.junit.*;
+import org.picocontainer.*;
+import org.picocontainer.behaviors.*;
+
+import java.lang.reflect.Type;
+
+public class IntoTypeTestCase {
+
+ @Test
+ public void testThatIntoSetupCorrectlyForNestedInjectionViaAFactory() throws Exception {
+ MutablePicoContainer pico = new DefaultPicoContainer(new Caching());
+ pico.addAdapter(new AliceFactory());
+ pico.addComponent(Bob.class);
+ System.out.println("Going to ask pico for a Bob");
+ assertTrue(Bob.class.isAssignableFrom(Bob.class));
+ Bob bob = pico.getComponent(Bob.class);
+ assertNotNull(bob);
+ assertNotNull(bob.getAlice());
+ }
+
+
+ public static interface Alice {
+ }
+
+
+ public static class AliceImpl implements Alice {
+ }
+
+ public static class Bob {
+
+ private Alice alice;
+
+ public Bob(Alice alice) {
+ System.out.println("Bob gets an Alice: " + alice);
+ this.alice = alice;
+ }
+
+ public Alice getAlice() {
+ return alice;
+ }
+
+ }
+
+
+ public static class AliceFactory extends FactoryInjector<Alice> {
+ @Override
+ public Alice getComponentInstance(PicoContainer container, Type into) {
+ // System.out.println("Manufacturing an Alice for " + ((InjectInto) into).getIntoClass());
+ if (Bob.class.isAssignableFrom(((InjectInto) into).getIntoClass())) {
+ return new AliceImpl();
+ } else {
+ fail("Expected a " + Bob.class + ", but got a " + into + " instead.");
+ return null;
+ }
+ }
+
+ }
+
+
+}
Property changes on: java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/IntoTypeTestCase.java
___________________________________________________________________
Name: svn:executable
+ *

----------

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.