Example #1
0
        public T CreateProxyWithTarget <T>(T uncachedComponent, ConfigurationForType configurationForType) where T : class
        {
            var cacheInterceptor = new CacheInterceptor(_cache, configurationForType);
            var options          = new ProxyGenerationOptions(new CacheProxyGenerationHook(configurationForType.CachedMethods));

            options.AddMixinInstance(createCachingComponent(configurationForType));
            return(typeof(T).IsClass ?
                   generator.CreateClassProxyWithTarget(uncachedComponent, options, cacheInterceptor) :
                   generator.CreateInterfaceProxyWithTarget(uncachedComponent, options, cacheInterceptor));
        }
Example #2
0
        public T CreateProxy <T>(ConfigurationForType configurationForType, params object[] parameters) where T : class
        {
            var type             = typeof(T);
            var cacheInterceptor = new CacheInterceptor(_cache, configurationForType);
            var options          = new ProxyGenerationOptions(new CacheProxyGenerationHook(configurationForType.CachedMethods));

            options.AddMixinInstance(createCachingComponent(configurationForType));
            try
            {
                if (type.IsClass)
                {
                    return((T)generator.CreateClassProxy(configurationForType.ComponentType.ConcreteType, options, parameters, cacheInterceptor));
                }
                var target = Activator.CreateInstance(configurationForType.ComponentType.ConcreteType, parameters);
                return(generator.CreateInterfaceProxyWithTarget((T)target, options, cacheInterceptor));
            }
            catch (MissingMethodException createInstanceEx)
            {
                throw new ArgumentException("Cannot instantiate proxy", createInstanceEx);
            }
        }