forked from ccnet/CruiseControl.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCachingImplementationResolver.cs
More file actions
41 lines (37 loc) · 1.04 KB
/
Copy pathCachingImplementationResolver.cs
File metadata and controls
41 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
namespace Objection
{
public class CachingImplementationResolver : ImplementationResolver
{
private readonly ImplementationResolver decoratoredResolver;
private readonly TypeToTypeMap resolvedTypeCache;
public CachingImplementationResolver(ImplementationResolver decoratoredResolver, TypeToTypeMap resolvedTypeCache)
{
this.decoratoredResolver = decoratoredResolver;
this.resolvedTypeCache = resolvedTypeCache;
}
public Type ResolveImplementation(Type baseType)
{
Type resolvedType = resolvedTypeCache[baseType];
if (resolvedType == null)
{
resolvedType = AllowOneThreadPerAppDomainToDoResolution(baseType);
}
return resolvedType;
}
private Type AllowOneThreadPerAppDomainToDoResolution(Type baseType)
{
Type resolvedType;
lock (baseType)
{
resolvedType = resolvedTypeCache[baseType];
if (resolvedType == null)
{
resolvedType = decoratoredResolver.ResolveImplementation(baseType);
resolvedTypeCache[baseType] = resolvedType;
}
}
return resolvedType;
}
}
}