Exemple #1
0
 public static void Register(Type interfaceType, ObjectRefProxyFactory proxyFactory)
 {
     Validate.Begin().IsNotNull<Type>(interfaceType, "interfaceType").IsNotNull<ObjectRefProxyFactory>(proxyFactory, "proxyFactory").Check();
     if (!canRegister)
     {
         ExceptionUtil.ThrowInvalidOperationException("proxy registration has been closed");
     }
     if (staticInterfaceTypeToProxyFactoryMap.ContainsKey(interfaceType))
     {
         if (staticInterfaceTypeToProxyFactoryMap[interfaceType] == proxyFactory)
         {
             return;
         }
         ExceptionUtil.ThrowArgumentException($"A proxy for '{interfaceType.FullName}' has already been registered with a different proxyFactory instance");
     }
     staticInterfaceTypeToProxyFactoryMap.Add(interfaceType, proxyFactory);
 }
Exemple #2
0
 public static ObjectRefProxy Create(Type interfaceType, IObjectRef objectRef, ObjectRefProxyOptions proxyOptions)
 {
     Validate.Begin().IsNotNull<Type>(interfaceType, "interfaceType").IsNotNull<IObjectRef>(objectRef, "objectRef").Check();
     if (interfaceType.ContainsGenericParameters)
     {
         ExceptionUtil.ThrowArgumentException($"Only closed generic interface types are allowed (interfaceType = '{interfaceType.FullName}')");
     }
     if (interfaceType == typeof(IObjectRef))
     {
         return new ObjectRefProxy(objectRef, proxyOptions);
     }
     ObjectRefProxyFactory orAdd = null;
     if (!staticInterfaceTypeToProxyFactoryMap.TryGetValue(interfaceType, out orAdd) && !dynamicInterfaceTypeToProxyFactoryMap.TryGetValue(interfaceType, out orAdd))
     {
         orAdd = dynamicInterfaceTypeToProxyFactoryMap.GetOrAdd(interfaceType, createProxyFactory);
         if (orAdd.IsNullReference<ObjectRefProxyFactory>())
         {
             ExceptionUtil.ThrowInvalidOperationException($"There is no proxy registered for '{interfaceType.FullName}'");
         }
     }
     return orAdd.CreateProxy(objectRef, proxyOptions);
 }