diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs index f16a716a..1ea1dff2 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs @@ -1156,22 +1156,15 @@ namespace Spring.Objects.Factory.Support CheckDependencies(name, definition, filteredPropInfo, properties); } - private static void CheckDependencies(string name, IConfigurableObjectDefinition definition, PropertyInfo[] filteredPropInfo, IPropertyValues properties) + private void CheckDependencies(string name, IConfigurableObjectDefinition definition, PropertyInfo[] filteredPropInfo, IPropertyValues properties) { DependencyCheckingMode dependencyCheck = definition.DependencyCheck; - foreach (PropertyInfo property in filteredPropInfo) + PropertyInfo[] unsatisfiedDependencies = AutowireUtils.GetUnsatisfiedDependencies(filteredPropInfo, properties, dependencyCheck); + + if (unsatisfiedDependencies.Length > 0) { - if (property.CanWrite && properties.GetPropertyValue(property.Name) == null) - { - bool isSimple = ObjectUtils.IsSimpleProperty(property.PropertyType); - bool unsatisfied = (dependencyCheck == DependencyCheckingMode.All) || (isSimple && dependencyCheck == DependencyCheckingMode.Simple) - || (!isSimple && dependencyCheck == DependencyCheckingMode.Objects); - if (unsatisfied) - { - throw new UnsatisfiedDependencyException(definition.ResourceDescription, name, property.Name, - "Set this property value or disable dependency checking for this object."); - } - } + throw new UnsatisfiedDependencyException(definition.ResourceDescription, name, unsatisfiedDependencies[0].Name, + "Set this property value or disable dependency checking for this object."); } } diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/AutowireUtils.cs b/src/Spring/Spring.Core/Objects/Factory/Support/AutowireUtils.cs index d0124793..58dd011c 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Support/AutowireUtils.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Support/AutowireUtils.cs @@ -349,5 +349,28 @@ namespace Spring.Objects.Factory.Support { return new SimpleAutowireCandidateResolver(); } + + /// + /// Returns the list of that are not satisfied by . + /// + /// the filtered list. Is never null + public static PropertyInfo[] GetUnsatisfiedDependencies(PropertyInfo[] propertyInfos, IPropertyValues properties, DependencyCheckingMode dependencyCheck) + { + ArrayList unsatisfiedDependenciesList = new ArrayList(); + foreach (PropertyInfo property in propertyInfos) + { + if (property.CanWrite && properties.GetPropertyValue(property.Name) == null) + { + bool isSimple = ObjectUtils.IsSimpleProperty(property.PropertyType); + bool unsatisfied = (dependencyCheck == DependencyCheckingMode.All) || (isSimple && dependencyCheck == DependencyCheckingMode.Simple) + || (!isSimple && dependencyCheck == DependencyCheckingMode.Objects); + if (unsatisfied) + { + unsatisfiedDependenciesList.Add(property); + } + } + } + return (PropertyInfo[])unsatisfiedDependenciesList.ToArray(typeof(PropertyInfo)); + } } } \ No newline at end of file