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); }
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); } }
public static IMethodLevelBehavior <T> Create <A>(Type beanType, AnnotationCache <A> annotationCache, Type behaviourType, IBehaviorTypeExtractor <A, T> behaviourTypeExtractor, IBeanContextFactory beanContextFactory, IServiceContext beanContext) where A : Attribute { BehaviorKey key = new BehaviorKey(beanType, behaviourType); IMethodLevelBehavior <T> behavior = (IMethodLevelBehavior <T>)beanTypeToBehavior.Get(key); if (behavior != null) { if (behavior == noBehavior) { return(null); } return(behavior); } A annotation = annotationCache.GetAnnotation(beanType); if (annotation == null) { beanTypeToBehavior.Put(key, noBehavior); return(null); } T defaultBehaviour = behaviourTypeExtractor.ExtractBehaviorType(annotation); MethodLevelHashMap <T> methodLevelBehaviour = null; MethodInfo[] methods = ReflectUtil.GetMethods(beanType); for (int a = methods.Length; a-- > 0;) { MethodInfo method = methods[a]; A annotationOnMethod = annotationCache.GetAnnotation(method); if (annotationOnMethod != null) { if (methodLevelBehaviour == null) { methodLevelBehaviour = new MethodLevelHashMap <T>(); } T behaviourTypeOnMethod = behaviourTypeExtractor.ExtractBehaviorType(annotationOnMethod); if (behaviourTypeOnMethod != null) { methodLevelBehaviour.Put(method, behaviourTypeOnMethod); } } } if (methodLevelBehaviour == null) { methodLevelBehaviour = new MethodLevelHashMap <T>(0); } behavior = new MethodLevelBehavior <T>(defaultBehaviour, methodLevelBehaviour); beanTypeToBehavior.Put(key, behavior); return(behavior); }
protected override ICascadedInterceptor HandleServiceIntern(Ioc.Factory.IBeanContextFactory beanContextFactory, Ioc.IServiceContext beanContext, Ioc.Config.IBeanConfiguration beanConfiguration, System.Type type, System.Collections.Generic.ISet <System.Type> requestedTypes) { MergeContext mergeContext = mergeContextCache.GetAnnotation(type); if (mergeContext == null) { return(null); } IMethodLevelBehavior <Attribute> behavior = CreateInterceptorModeBehavior(type); MergeInterceptor mergeInterceptor = new MergeInterceptor(); if (beanContext.IsRunning) { return(beanContext.RegisterWithLifecycle(mergeInterceptor) // .PropertyValue("Behavior", behavior) // .IgnoreProperties("ServiceName") // .Finish()); } beanContextFactory.RegisterWithLifecycle(mergeInterceptor) // .PropertyValue("Behavior", behavior) // .IgnoreProperties("ServiceName"); return(mergeInterceptor); }
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); }