/// <summary> /// 获取指定类型的动态代理 /// </summary> /// <param name="genericType"></param> /// <param name="serviceType"></param> /// <returns></returns> private object GetProxyService(Type genericType, Type serviceType) { object result = null; Type proxyType = null; object proxy = null; if (genericType == typeof(IInvocation <>)) { proxyType = serviceType.GetGenericArguments()[0]; proxy = DynamicProxy.Create(proxyType); result = InvocationProxyFactory.CreateInvocation(proxyType, proxy); } else if (genericType == typeof(IInvocation <,>)) { proxyType = serviceType.GetGenericArguments()[0]; var interceptorType = serviceType.GetGenericArguments()[1]; IMethodInterceptor methodInterceptor = (IMethodInterceptor) _serviceProvider.GetRequiredService(interceptorType); proxy = DynamicProxy.CreateWithInterceptor(proxyType, methodInterceptor); result = InvocationProxyFactory.CreateInvocationWithInterceptor(proxyType, proxy, methodInterceptor); } return(result); }