File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
src/Spring/Spring.Web.Mvc3 Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ public class SpringMvcDependencyResolver : IDependencyResolver
27
27
28
28
private static readonly ILog logger = LogManager . GetLogger ( typeof ( SpringMvcDependencyResolver ) ) ;
29
29
private readonly ConcurrentBag < Type > _nonResolvableTypes = new ConcurrentBag < Type > ( ) ;
30
+ private readonly ConcurrentDictionary < Type , string > _resolvedNames = new ConcurrentDictionary < Type , string > ( ) ;
30
31
31
32
/// <summary>
32
33
/// Initializes a new instance of the <see cref="SpringMvcDependencyResolver"/> class.
@@ -103,11 +104,20 @@ public object GetService(Type serviceType)
103
104
}
104
105
else
105
106
{
106
- // fall back to more expensive searching with type
107
- var matchingServices = ApplicationContext . GetObjectNamesForType ( serviceType ) ;
108
- if ( matchingServices . Count > 0 )
107
+ string resolvedName ;
108
+ if ( _resolvedNames . TryGetValue ( serviceType , out resolvedName ) )
109
109
{
110
- service = ApplicationContext . GetObject ( matchingServices [ 0 ] ) ;
110
+ service = ApplicationContext . GetObject ( resolvedName ) ;
111
+ }
112
+ else
113
+ {
114
+ // fall back to more expensive searching with type
115
+ var matchingServices = ApplicationContext . GetObjectNamesForType ( serviceType ) ;
116
+ if ( matchingServices . Count > 0 )
117
+ {
118
+ _resolvedNames . TryAdd ( serviceType , matchingServices [ 0 ] ) ;
119
+ service = ApplicationContext . GetObject ( matchingServices [ 0 ] ) ;
120
+ }
111
121
}
112
122
}
113
123
You can’t perform that action at this time.
0 commit comments