From 01d4db4e51903e65dd7926a6a5e6d48747f52366 Mon Sep 17 00:00:00 2001 From: Steve Bohlen Date: Tue, 3 Feb 2015 02:10:54 -0500 Subject: [PATCH] avoid repeated calls to GetObjectNamesForType in DependencyResolver --- .../SpringMvcDependencyResolver.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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]); + } } }