protected override IEnumerable <ConsumerExecutorDescriptor> FindConsumersFromInterfaceTypes(IServiceProvider provider) { var executorDescriptorList = new List <ConsumerExecutorDescriptor>(); using (var scoped = provider.CreateScope()) { var scopedProvider = scoped.ServiceProvider; var consumerServices = scopedProvider.GetServices <ICapSubscribe>(); foreach (var service in consumerServices) { var serviceType = service.GetType(); // Castle dynamic proxy... TypeInfo typeInfo = ProxyServices.IsDynamicProxy(serviceType) ? ProxyUtil.GetUnproxiedType(service).GetTypeInfo() : serviceType.GetTypeInfo(); if (!typeof(ICapSubscribe).GetTypeInfo().IsAssignableFrom(typeInfo)) { continue; } executorDescriptorList.AddRange(GetTopicAttributesDescription(typeInfo)); } return(executorDescriptorList); } }
/// <summary> /// 获取类型代理前的类型 /// </summary> /// <param name="type"></param> /// <returns></returns> public static Type GetRawType(Type type) { while (ProxyServices.IsDynamicProxy(type)) { type = type.BaseType; } return(type); }
public void OnBehalfAware_ProxyGenarationHook_works_on_dependencies() { OnBehalfAwareProxyGenerationHook.target = null; Container.Register(Component.For <OnBehalfAwareProxyGenerationHook>().LifeStyle.Transient, Component.For <StandardInterceptor>().LifeStyle.Transient, Component.For <UsesSimpleComponent1>().LifeStyle.Transient, Component.For <SimpleComponent1>().LifeStyle.Transient .Interceptors <StandardInterceptor>() .Proxy.Hook(h => h.Service <OnBehalfAwareProxyGenerationHook>())); var service = Container.Resolve <UsesSimpleComponent1>(); Assert.IsTrue(ProxyServices.IsDynamicProxy(service.Dependency.GetType())); Assert.IsNotNull(OnBehalfAwareProxyGenerationHook.target); Assert.AreEqual(typeof(SimpleComponent1), OnBehalfAwareProxyGenerationHook.target.Services.Single()); }
public void InterceptorSelector_can_be_OnBehalfAware() { OnBehalfAwareInterceptorSelector.target = null; Container.Register(Component.For <OnBehalfAwareInterceptorSelector>().LifeStyle.Transient, Component.For <StandardInterceptor>().LifeStyle.Transient, Component.For <ISimpleService>() .ImplementedBy <SimpleService>() .LifeStyle.Transient .Interceptors <StandardInterceptor>() .SelectInterceptorsWith(s => s.Service <OnBehalfAwareInterceptorSelector>())); var service = Container.Resolve <ISimpleService>(); Assert.IsTrue(ProxyServices.IsDynamicProxy(service.GetType())); Assert.IsNotNull(OnBehalfAwareInterceptorSelector.target); Assert.AreEqual(typeof(ISimpleService), OnBehalfAwareInterceptorSelector.target.Services.Single()); }