diff --git a/src/Spring/Spring.Web.Mvc3/SpringMvcDependencyResolver.cs b/src/Spring/Spring.Web.Mvc3/SpringMvcDependencyResolver.cs index 65043652..f18f15a7 100644 --- a/src/Spring/Spring.Web.Mvc3/SpringMvcDependencyResolver.cs +++ b/src/Spring/Spring.Web.Mvc3/SpringMvcDependencyResolver.cs @@ -27,6 +27,7 @@ namespace Spring.Web.Mvc private static readonly ILog logger = LogManager.GetLogger(typeof(SpringMvcDependencyResolver)); private readonly ConcurrentBag _nonResolvableTypes = new ConcurrentBag(); + private readonly ConcurrentDictionary _resolvedNames = new ConcurrentDictionary(); /// /// Initializes a new instance of the class. @@ -103,11 +104,20 @@ namespace Spring.Web.Mvc } else { - // fall back to more expensive searching with type - var matchingServices = ApplicationContext.GetObjectNamesForType(serviceType); - if (matchingServices.Count > 0) + string resolvedName; + if (_resolvedNames.TryGetValue(serviceType, out resolvedName)) { - service = ApplicationContext.GetObject(matchingServices[0]); + service = ApplicationContext.GetObject(resolvedName); + } + else + { + // fall back to more expensive searching with type + var matchingServices = ApplicationContext.GetObjectNamesForType(serviceType); + if (matchingServices.Count > 0) + { + _resolvedNames.TryAdd(serviceType, matchingServices[0]); + service = ApplicationContext.GetObject(matchingServices[0]); + } } }