File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
src/protobuf-net.Grpc/Configuration Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 1
- using System ;
1
+ using ProtoBuf . Grpc . Internal ;
2
+ using System ;
3
+ using System . Collections . Concurrent ;
2
4
using System . Collections . Generic ;
3
5
using System . Reflection ;
4
- using ProtoBuf . Grpc . Internal ;
5
6
6
7
namespace ProtoBuf . Grpc . Configuration
7
8
{
@@ -19,13 +20,14 @@ public class ServiceBinder
19
20
/// </summary>
20
21
protected ServiceBinder ( ) { }
21
22
22
- private readonly Dictionary < Type , InterfaceMapping > _map = new Dictionary < Type , InterfaceMapping > ( ) ;
23
- private InterfaceMapping GetMap ( Type contractType , Type serviceType )
23
+ private static readonly ConcurrentDictionary < Type , InterfaceMapping > s_map = new ConcurrentDictionary < Type , InterfaceMapping > ( ) ;
24
+ private static InterfaceMapping GetMap ( Type contractType , Type serviceType )
24
25
{
25
- if ( ! _map . TryGetValue ( contractType , out var interfaceMapping ) )
26
- {
26
+ if ( ! s_map . TryGetValue ( contractType , out var interfaceMapping ) )
27
+ { // note: it doesn't matter if this ends up getting called more than once
28
+ // in a race condition - we don't need to block etc (the result will be compatible)
27
29
interfaceMapping = serviceType . GetInterfaceMap ( contractType ) ;
28
- _map [ contractType ] = interfaceMapping ;
30
+ s_map [ contractType ] = interfaceMapping ;
29
31
}
30
32
return interfaceMapping ;
31
33
}
You can’t perform that action at this time.
0 commit comments