diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs b/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs index 47814eb0..27ee3007 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs @@ -1,7 +1,7 @@ #region License /* - * Copyright © 2002-2011 the original author or authors. + * Copyright © 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -223,36 +223,34 @@ namespace Spring.Objects.Factory.Support protected override IList GetDependingObjectNames(string objectName) { List dependingObjectNames = new List(); - IList allObjectDefinitionNames = GetObjectDefinitionNames(); - foreach (string name in allObjectDefinitionNames) - { - if (ContainsObjectDefinition(name)) - { - RootObjectDefinition rod = GetMergedObjectDefinition(name, false); - if (rod.DependsOn != null) - { - HashSet dependsOn = new HashSet(rod.DependsOn); - if (dependsOn.Contains(objectName)) - { - #region Instrumentation - - if (log.IsDebugEnabled) - { - log.Debug(string.Format( - CultureInfo.InvariantCulture, - "Found depending object '{0}' for object '{1}'.", - name, objectName)); - } - - #endregion - - dependingObjectNames.Add(name); - } - } - } - } - return dependingObjectNames; - } + if (dependingObjectNamesCache == null) + { + dependingObjectNamesCache = new Dictionary>(); + IList allObjectDefinitionNames = GetObjectDefinitionNames(); + foreach (string name in allObjectDefinitionNames) + { + if (ContainsObjectDefinition(name)) + { + RootObjectDefinition rod = GetMergedObjectDefinition(name, false); + if (rod.DependsOn != null) + { + foreach (var dependsOnName in rod.DependsOn) + { + if (!dependingObjectNamesCache.TryGetValue(dependsOnName, out dependingObjectNames)) + { + dependingObjectNames = new List(); + dependingObjectNamesCache.Add(dependsOnName, dependingObjectNames); + } + dependingObjectNames.Add(name); + } + } + } + } + } + if (dependingObjectNamesCache.TryGetValue(objectName, out dependingObjectNames)) + return dependingObjectNames; + return new string[]{}; + } /// /// Check whether the specified object matches the supplied . @@ -294,6 +292,11 @@ namespace Spring.Objects.Factory.Support #region Fields + /// + /// The mapping of object depending object names, keyed by object name. + /// + private IDictionary> dependingObjectNamesCache; + /// /// The instance for this class. ///