Пример #1
0
        public T CreateProxy <T>(ConfigurationForType configurationForType, params object[] parameters) where T : class
        {
            var target      = createTarget(configurationForType.ComponentType.ConcreteType, parameters);
            var interceptor = new CacheInterceptor(_cache, configurationForType, target);

            return(proxyFactory.CreateProxy <T>(interceptor, typeof(ICachingComponent)));
        }
Пример #2
0
 public CacheInterceptor(CacheAdapter cache, ConfigurationForType configurationForType, object target)
 {
     _cache = cache;
     _configurationForType = configurationForType;
     _target           = target;
     _cachingComponent = new CachingComponent(cache, configurationForType.CacheKey, configurationForType);
 }
Пример #3
0
 public FluentBuilder(CacheBuilder cacheBuilder,
                      IDictionary <Type, ConfigurationForType> cachedMethods,
                      ConfigurationForType details)
 {
     _cacheBuilder  = cacheBuilder;
     _cachedMethods = cachedMethods;
     _details       = details;
 }
Пример #4
0
 public FluentBuilder(CacheBuilder cacheBuilder,
                      IDictionary <Type, ConfigurationForType> cachedMethods,
                      ConfigurationForType details,
                      ProxyValidator proxyValidator)
 {
     _cacheBuilder   = cacheBuilder;
     _cachedMethods  = cachedMethods;
     _details        = details;
     _proxyValidator = proxyValidator;
 }
Пример #5
0
        /// <summary>
        /// Creates a caching component for <see cref="T"/>.
        /// </summary>
        /// <param name="typeAsCacheKey">
        /// Gives a name to this type to be used as cache key.
        /// </param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public IFluentBuilder <T> For <T>(string typeAsCacheKey)
        {
            var concreteType = typeof(T);
            var details      = new ConfigurationForType(concreteType, typeAsCacheKey);

            _details.Add(details);
            var fluentBuilder = new FluentBuilder <T>(this, _configuredTypes, details, _proxyValidator);

            return(fluentBuilder);
        }
Пример #6
0
 public CacheInterceptor(CacheAdapter cache,
                         ICacheKey cacheKey,
                         ILockObjectGenerator lockObjectGenerator,
                         ConfigurationForType configurationForType)
 {
     _cache                = cache;
     _cacheKey             = cacheKey;
     _lockObjectGenerator  = lockObjectGenerator;
     _configurationForType = configurationForType;
 }
Пример #7
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));
        }
Пример #8
0
 public CacheInterceptor(CacheAdapter cache,
                         ICacheKey cacheKey,
                         ILockObjectGenerator lockObjectGenerator,
                         ConfigurationForType configurationForType,
                         object target)
 {
     _cache                = cache;
     _cacheKey             = cacheKey;
     _lockObjectGenerator  = lockObjectGenerator;
     _configurationForType = configurationForType;
     _target               = target;
     _cachingComponent     = new CachingComponent(cache, cacheKey, configurationForType);
 }
Пример #9
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);
            }
        }
Пример #10
0
 public CacheInterceptor(CacheAdapter cache,
                         ConfigurationForType configurationForType)
 {
     _cache = cache;
     _configurationForType = configurationForType;
 }
Пример #11
0
        public T CreateProxyWithTarget <T>(T uncachedComponent, ConfigurationForType configurationForType) where T : class
        {
            var interceptor = new CacheInterceptor(_cache, configurationForType, uncachedComponent);

            return(proxyFactory.CreateProxy <T>(interceptor, typeof(ICachingComponent)));
        }
Пример #12
0
 public CacheProxyGenerationHook(ConfigurationForType methodData)
 {
     _methodData = methodData;
 }
Пример #13
0
 private ICachingComponent createCachingComponent(ConfigurationForType configurationForType)
 {
     return(new CachingComponent(_cache, configurationForType.CacheKey, configurationForType));
 }
Пример #14
0
 public T CreateProxyWithTarget <T>(T uncachedComponent, ConfigurationForType configurationForType) where T : class
 {
     throw new System.NotImplementedException();
 }
Пример #15
0
 public T CreateProxy <T>(ConfigurationForType configurationForType, params object[] parameters) where T : class
 {
     throw new NotSupportedException("This test creates proxies. Please derive from " + typeof(FullTest).Name + " instead.");
 }
Пример #16
0
 public T CreateProxyWithTarget <T>(T uncachedComponent, ConfigurationForType configurationForType) where T : class
 {
     throw new NotSupportedException("This test creates proxies. Please derive from " + typeof(FullTest).Name + " instead.");
 }
Пример #17
0
 public T CreateProxy <T>(ConfigurationForType configurationForType, params object[] parameters) where T : class
 {
     throw new System.NotImplementedException();
 }