public static TService CreateInterfaceProxy <TService>(this IProxyGenerator proxyGenerator, TService implementationInstance) where TService : class { if (proxyGenerator == null) { throw new ArgumentNullException(nameof(proxyGenerator)); } return((TService)proxyGenerator.CreateInterfaceProxy(typeof(TService), implementationInstance)); }
public ConnectionMultiplexerProvider(IProxyGenerator proxyGenerator, IOptionAccessor <RedisProfilingOptions> optionAccessor) { if (optionAccessor == null) { throw new ArgumentNullException(nameof(IOptionAccessor <RedisProfilingOptions>)); } var connectionMultiplexer = StackExchange.Redis.ConnectionMultiplexer.Connect(optionAccessor.Value.GetConfigurationOptions()); connectionMultiplexer.RegisterProfiler(new AspectRedisDatabaseProfiler()); _connectionMultiplexer = proxyGenerator.CreateInterfaceProxy <IConnectionMultiplexer>(connectionMultiplexer); }
public void TestMethod1() { ProxyGeneratorBuilder proxyGeneratorBuilder = new ProxyGeneratorBuilder(); IProxyGenerator proxyGenerator = proxyGeneratorBuilder.Build(); //创建ICanService的代理类 CreateInterfaceProxy<T> 只会mock接口 不会调用PeopleCanServcie的方法 // CreateInterfaceProxy<Tinterface,TImplate> 会模拟接口也会调用PeopleCanService的方法 ICanService canServiceProxy = proxyGenerator.CreateInterfaceProxy <ICanService, PeopleCanServcie>(); Console.WriteLine(canServiceProxy.GetType().ToString()); canServiceProxy.SayHello(); canServiceProxy.SayBye(); }
public EntityProxy() { ProxyGeneratorBuilder proxyGeneratorBuilder = new ProxyGeneratorBuilder(); IProxyGenerator proxyGenerator = proxyGeneratorBuilder.Build(); SampleInterface sampleInterface = proxyGenerator.CreateInterfaceProxy <SampleInterface, SampleClass>(); Console.WriteLine(sampleInterface); sampleInterface.Foo(); Console.ReadKey(); System.Data.IDbConnection con = null; //proxyGenerator.CreateClassProxy(); }
public static object CreateInterfaceProxy(this IProxyGenerator proxyGenerator, Type serviceType, Type implementationType, params object[] args) { if (proxyGenerator == null) { throw new ArgumentNullException(nameof(proxyGenerator)); } if (serviceType == null) { throw new ArgumentNullException(nameof(serviceType)); } if (implementationType == null) { throw new ArgumentNullException(nameof(implementationType)); } return(proxyGenerator.CreateInterfaceProxy(serviceType, Activator.CreateInstance(implementationType, args ?? ArrayUtils.Empty <object>()))); }
public object CreateInterfaceProxy(Type serviceType) { return(_proxyGenerator.CreateInterfaceProxy(serviceType)); }
public T CreateProxyInstance <T>() where T : class { var proxyInstance = ProxyGenerator.CreateInterfaceProxy <T>(); return(proxyInstance); }