cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r953514 - in /cayenne/main/trunk/framework/cayenne-di-unpublished/src: main/java/org/apache/cayenne/di/spi/ test/java/org/apache/cayenne/di/mock/ test/java/org/apache/cayenne/di/spi/
Date Fri, 11 Jun 2010 00:32:06 GMT
Author: aadamchik
Date: Fri Jun 11 00:32:06 2010
New Revision: 953514

URL: http://svn.apache.org/viewvc?rev=953514&view=rev
Log:
a bug in DI circular dependency code

Added:
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/mock/MockImplementation2_I3Dependency.java
Modified:
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/FieldInjectingProvider.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorCircularInjectionTest.java

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/FieldInjectingProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/FieldInjectingProvider.java?rev=953514&r1=953513&r2=953514&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/FieldInjectingProvider.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/FieldInjectingProvider.java
Fri Jun 11 00:32:06 2010
@@ -88,9 +88,12 @@ class FieldInjectingProvider<T> implemen
             value = injector.getProvider(Key.get(objectClass, bindingName));
         }
         else {
-            stack.push(bindingKey);
+            
+            Key<?> key = Key.get(fieldType, bindingName);
+            
+            stack.push(key);
             try {
-                value = injector.getInstance(Key.get(fieldType, bindingName));
+                value = injector.getInstance(key);
             }
             finally {
                 stack.pop();

Added: cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/mock/MockImplementation2_I3Dependency.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/mock/MockImplementation2_I3Dependency.java?rev=953514&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/mock/MockImplementation2_I3Dependency.java
(added)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/mock/MockImplementation2_I3Dependency.java
Fri Jun 11 00:32:06 2010
@@ -0,0 +1,35 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.di.mock;
+
+import org.apache.cayenne.di.Inject;
+
+public class MockImplementation2_I3Dependency implements MockInterface2 {
+
+    @Inject
+    private MockInterface3 delegate;
+
+    public String getAlteredName() {
+        return "dT" + delegate.getName();
+    }
+
+    public String getName() {
+        return "dT";
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorCircularInjectionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorCircularInjectionTest.java?rev=953514&r1=953513&r2=953514&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorCircularInjectionTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorCircularInjectionTest.java
Fri Jun 11 00:32:06 2010
@@ -28,8 +28,11 @@ import org.apache.cayenne.di.mock.MockIm
 import org.apache.cayenne.di.mock.MockImplementation1_DepOn2Provider;
 import org.apache.cayenne.di.mock.MockImplementation2;
 import org.apache.cayenne.di.mock.MockImplementation2_Constructor;
+import org.apache.cayenne.di.mock.MockImplementation2_I3Dependency;
+import org.apache.cayenne.di.mock.MockImplementation3;
 import org.apache.cayenne.di.mock.MockInterface1;
 import org.apache.cayenne.di.mock.MockInterface2;
+import org.apache.cayenne.di.mock.MockInterface3;
 
 public class DefaultInjectorCircularInjectionTest extends TestCase {
 
@@ -99,4 +102,27 @@ public class DefaultInjectorCircularInje
             fail("Circular dependency is not detected, causing stack overflow");
         }
     }
+
+    public void testConstructorInjection_WithFieldInjectionDeps() {
+
+        Module module = new Module() {
+
+            public void configure(Binder binder) {
+                binder.bind(MockInterface1.class).to(
+                        MockImplementation1_DepOn2Constructor.class);
+                binder.bind(MockInterface2.class).to(
+                        MockImplementation2_I3Dependency.class);
+                binder.bind(MockInterface3.class).to(MockImplementation3.class);
+            }
+        };
+
+        DefaultInjector injector = new DefaultInjector(module);
+
+        try {
+            injector.getInstance(MockInterface1.class);
+        }
+        catch (ConfigurationException e) {
+            fail("Circular dependency is detected incorrectly: " + e.getMessage());
+        }
+    }
 }



Mime
View raw message