コード例 #1
0
 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));
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
ファイル: EntityProxy.cs プロジェクト: lulzzz/WCloud
        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();
        }
コード例 #5
0
 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>())));
 }
コード例 #6
0
 public object CreateInterfaceProxy(Type serviceType)
 {
     return(_proxyGenerator.CreateInterfaceProxy(serviceType));
 }
コード例 #7
0
        public T CreateProxyInstance <T>() where T : class
        {
            var proxyInstance = ProxyGenerator.CreateInterfaceProxy <T>();

            return(proxyInstance);
        }