Exemple #1
0
        protected ICascadedInterceptor HandleServiceClientAnnotation(AnnotationEntry <ServiceClientAttribute> serviceClientAnnotation, IBeanContextFactory beanContextFactory, IServiceContext beanContext,
                                                                     IBeanConfiguration beanConfiguration, Type type)
        {
            String serviceName = ExtractServiceName(serviceClientAnnotation.Annotation.Name, serviceClientAnnotation.DeclaringType);

            IMethodLevelBehavior <Attribute> behavior = CreateInterceptorModeBehavior(type);

            CacheInterceptor interceptor = new CacheInterceptor();

            if (beanContext.IsRunning)
            {
                interceptor = beanContext.RegisterWithLifecycle(interceptor) //
                              .PropertyValue("ServiceName", serviceName)     //
                              .PropertyValue("Behavior", behavior)           //
                              .Finish();
            }
            else
            {
                beanContextFactory.RegisterWithLifecycle(interceptor) //
                .PropertyValue("ServiceName", serviceName)            //
                .PropertyValue("Behavior", behavior);
            }

            if (Log.InfoEnabled)
            {
                Log.Info("Creating application service stub for service '" + serviceName + "' accessing with '" + serviceClientAnnotation.DeclaringType.FullName + "'");
            }
            return(interceptor);
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheProxyFactory"/>.
 /// </summary>
 /// <param name="proxyGenerator">The <see cref="Castle.DynamicProxy.ProxyGenerator"/>.</param>
 /// <param name="cacheInterceptor">The <see cref="Interceptors.CacheInterceptor"/>.</param>
 public CacheProxyFactory(
     ProxyGenerator proxyGenerator,
     CacheInterceptor cacheInterceptor)
 {
     ProxyGenerator   = proxyGenerator ?? throw new ArgumentNullException(nameof(proxyGenerator));
     CacheInterceptor = cacheInterceptor ?? throw new ArgumentNullException(nameof(cacheInterceptor));
 }
Exemple #3
0
 private static CacheTester GenerateTester()
 {
     var cacheInterceptor = new CacheInterceptor();
     cacheInterceptor.DefaultMarkerInstance = cacheInterceptor.DefaultMarkerInstance; // shut up code coverage
     var proxy = Factory.CreateClassProxy(typeof(CacheTester), cacheInterceptor);
     return (CacheTester)proxy;
 }
Exemple #4
0
        protected ICascadedInterceptor HandleServiceAnnotation(ServiceAttribute serviceAnnotation, IBeanContextFactory beanContextFactory, IServiceContext beanContext, IBeanConfiguration beanConfiguration, Type type)
        {
            if (serviceAnnotation.CustomExport)
            {
                // Do nothing if the service wants to be exported by some special way anywhere else
                return(null);
            }
            String beanName    = beanConfiguration.GetName();
            String serviceName = ExtractServiceName(serviceAnnotation.Name, type);

            if (!IsNetworkClientMode)
            {
                IMethodLevelBehavior <Attribute> behavior = CreateInterceptorModeBehavior(type);

                CacheInterceptor interceptor = new CacheInterceptor();
                if (beanContext.IsRunning)
                {
                    interceptor = beanContext.RegisterWithLifecycle(interceptor) //
                                  .PropertyValue("ServiceName", serviceName)     //
                                  .PropertyValue("Behavior", behavior)           //
                                  .IgnoreProperties("ProcessService")            //
                                  .Finish();
                    beanContext.Link(beanName).To <IServiceExtendable>().With(serviceName);
                }
                else
                {
                    beanContextFactory.RegisterWithLifecycle(interceptor) //
                    .PropertyValue("ServiceName", serviceName)            //
                    .PropertyValue("Behavior", behavior)                  //
                    .IgnoreProperties("ProcessService");
                    beanContextFactory.Link(beanName).To <IServiceExtendable>().With(serviceName);
                }
                if (Log.InfoEnabled)
                {
                    Log.Info("Registering application service '" + serviceName + "'");
                }
                return(interceptor);
            }
            else
            {
                if (Log.InfoEnabled)
                {
                    Log.Info("Registering application mock service '" + serviceName + "'");
                }
                if (beanContext.IsRunning)
                {
                    beanContext.Link(beanName).To <IServiceExtendable>().With(serviceName);
                }
                else
                {
                    beanContextFactory.Link(beanName).To <IServiceExtendable>().With(serviceName);
                }
                return(null);
            }
        }
        protected override ICascadedInterceptor HandleServiceIntern(IBeanContextFactory beanContextFactory, IServiceContext beanContext, IBeanConfiguration beanConfiguration, Type type, ISet <Type> requestedTypes)
        {
            CacheContext cacheContext = annotationCache.GetAnnotation(type);

            if (cacheContext == null)
            {
                return(null);
            }
            IMethodLevelBehavior <Attribute> cacheBehavior = CachePostProcessor.CreateInterceptorModeBehavior(type);

            CacheInterceptor interceptor = new CacheInterceptor();

            if (beanContext.IsRunning)
            {
                interceptor = beanContext.RegisterWithLifecycle(interceptor)     //
                              .PropertyValue("Behavior", cacheBehavior)          //
                              .IgnoreProperties("ProcessService", "ServiceName") //
                              .Finish();
            }
            else
            {
                beanContextFactory.RegisterWithLifecycle(interceptor) //
                .PropertyValue("Behavior", cacheBehavior)             //
                .IgnoreProperties("ProcessService", "ServiceName");
            }

            CacheType cacheType = cacheContext.CacheType;
            String    cacheProviderName;

            switch (cacheType)
            {
            case CacheType.PROTOTYPE:
            {
                cacheProviderName = CacheNamedBeans.CacheProviderPrototype;
                break;
            }

            case CacheType.SINGLETON:
            {
                cacheProviderName = CacheNamedBeans.CacheProviderSingleton;
                break;
            }

            case CacheType.THREAD_LOCAL:
            {
                cacheProviderName = CacheNamedBeans.CacheProviderThreadLocal;
                break;
            }

            case CacheType.DEFAULT:
            {
                return(interceptor);
            }

            default:
                throw new Exception("Not supported type: " + cacheType);
            }
            CacheContextInterceptor ccInterceptor = new CacheContextInterceptor();

            if (beanContext.IsRunning)
            {
                return(beanContext.RegisterWithLifecycle(ccInterceptor) //
                       .PropertyRef("CacheProvider", cacheProviderName) //
                       .PropertyValue("Target", interceptor)            //
                       .Finish());
            }
            beanContextFactory.RegisterWithLifecycle(ccInterceptor) //
            .PropertyRef("CacheProvider", cacheProviderName)        //
            .PropertyValue("Target", interceptor);
            return(ccInterceptor);
        }