public static ComponentRegistration <TService> TargetIsCommonDatastore <TService>( this ComponentRegistration <TService> registration) { ComponentRegistration <TService> result = registration; if (!typeof(IProxiedEntity).IsAssignableFrom(typeof(TService))) { result = result.Proxy.AdditionalInterfaces(typeof(IProxiedEntity)); } result = result.Interceptors(new InterceptorReference(typeof(EntityNameInterceptor))).Anywhere; return(result.Interceptors(new InterceptorReference(typeof(CommonPropertyStoreInterceptor))).Last); }
public static ComponentRegistration <T> ImplementedAsSplittedInterfaceBy <T>( this ComponentRegistration <T> componentRegistration, params Type[] by) where T : class { return(componentRegistration.Interceptors( WrapTypesIntoInterceptor(by).Concat(new[] { typeof(InterfaceSplittingBottomInterceptor) }).ToArray())); }
public static ComponentRegistration <T> ImplementedAsSplittedInterfaceBy <T, Impl1>( this ComponentRegistration <T> componentRegistration) where T : class { return(componentRegistration.Interceptors( typeof(InterfaceSplittingInterceptor <Impl1>), typeof(InterfaceSplittingBottomInterceptor))); }
public static ComponentRegistration <T> ImplementedAsSplittedInterface <T>(this ComponentRegistration <T> componentRegistration) where T : class { var interfaces = typeof(T).GetInterfaces(); return(componentRegistration.Interceptors( WrapTypesIntoInterceptor(interfaces).Concat(new[] { typeof(InterfaceSplittingBottomInterceptor) }).ToArray())); }
public void Apply(Component component, ComponentRegistration registration) { AbstractConfigurationRunner.Kernel.Register( Castle.MicroKernel.Registration.Component.For(interceptorType).OnlyNewServices() ); registration.Interceptors(InterceptorReference.ForType(interceptorType)).First .OverWrite(); }
public void Apply(Component component, ComponentRegistration registration) { AbstractConfigurationRunner.Kernel.Register( Castle.MicroKernel.Registration.Component.For(interceptorType).OnlyNewServices() ); registration.Interceptors(InterceptorReference.ForType(interceptorType)).First .OverWrite(); }
public static ComponentRegistration <T> At <T>(this ComponentRegistration <T> componentRegistration, string address, string remoteKey, string localKey) { componentRegistration = componentRegistration .Interceptors <InvocationInterceptor>() .AddAttributeDescriptor(ADDRESS, address) .AddAttributeDescriptor(REMOTE_KEY, remoteKey).Named(localKey); return(componentRegistration); }
public static ComponentRegistration <TService> EditableObjectBehavior <TService>( this ComponentRegistration <TService> componentRegistration) { ComponentRegistration <TService> result = componentRegistration; if (!typeof(IEditableObject).IsAssignableFrom(typeof(TService))) { result = result.Proxy.AdditionalInterfaces(typeof(IEditableObject)); } result = result.Interceptors(new InterceptorReference(typeof(EditableObjectInterceptor))) .Anywhere; return(result); }
public void Register(ServiceConfiguration service) { ComponentRegistration <object> component = Component.For(service.For); if (service.ToFactory != null) { ServiceConfiguration ctx = service; component = component.UsingFactoryMethod((k, cm, c) => ctx.ToFactory(new FactoryContext { RequestedType = c.RequestedType, Arguments = c.HasAdditionalArguments ? c.AdditionalArguments.Values.Cast <object>().ToArray() : null }), true); } else { component = component.ImplementedBy(service.To); } component = component.ToWindsorLifeTime(service.Lifetime); if (!string.IsNullOrEmpty(service.Name)) { component = component.Named(service.Name); } if (service.Dependencies.Any()) { var allDependencies = service.Dependencies.Select(dependency => Dependency.OnComponent(dependency.Key, dependency.Value)).ToArray(); component.DependsOn(allDependencies); } if (service.Interceptors.Any()) { var interceptorName = string.Format("interceptor_{0}_{1}", service.For.First().Name, Guid.NewGuid().ToString().Replace("-", string.Empty)); //Register interceptor itself by name container.Register(Component.For <RegistrationInterceptor>().Named(interceptorName) .DynamicParameters((k, c, p) => { p["context"] = c; return(null); }) .DependsOn( Dependency.OnValue("interceptions", service.Interceptors), Dependency.OnValue("container", container), Dependency.OnValue("context", null) ).LifestyleTransient() ); component.Interceptors(interceptorName); } container.Register(component); }
/// <summary> /// Add the PropertyChangeInterceptor to the component. /// </summary> /// <typeparam name="TService"></typeparam> /// <param name="registration"></param> /// <returns></returns> public static ComponentRegistration <TService> NotifyOnPropertyChange <TService>( this ComponentRegistration <TService> registration) { ComponentRegistration <TService> result = registration; if (!typeof(INotifyPropertyChanged).IsAssignableFrom(typeof(TService))) { result = result.Proxy.AdditionalInterfaces(typeof(INotifyPropertyChanged)); } result = result.Interceptors(new InterceptorReference(typeof(PropertyChangeInterceptor))) .Anywhere; return(result); }
/// <summary> /// Indicates that the specified component should be automatically implemented from /// the config. /// </summary> /// <typeparam name="T">The type of the interface to implement.</typeparam> /// <param name="registration">The registration.</param> /// <param name="configAction">Allows you to customize how the settings interface is implemented.</param> /// <returns>The registration.</returns> public static ComponentRegistration <T> FromAppConfig <T>(this ComponentRegistration <T> registration, Action <IConfigConfiguration <T> > configAction = null) where T : class { registration.Interceptors <AppConfigInterceptor>(); if (configAction != null) { var configuration = new ConfigConfiguration <T>(); configAction(configuration); registration.ExtendedProperties(new Property(AppConfigInterceptor.ComputedPropertiesKey, configuration.ComputedDictionary)); registration.ExtendedProperties(new Property(AppConfigInterceptor.PrefixKey, configuration.Prefix)); } return(registration); }
public static ComponentRegistration <T> EnableValidation <T>(this ComponentRegistration <T> component) where T : class { return(component.Interceptors <ValidationInterceptor>()); }
public ComponentRegistration <TClientService> WithHub <THub>() where THub : IHub { registration.Interceptors <StandardInterceptor>().SelectInterceptorsWith(new HubInterceptorSelector <THub>()); return(registration); }
public void Execute(ServiceContext context) { ComponentRegistration <object> component = Component.For(context.For); if (context.ToFactory != null) { ServiceContext ctx = context; component = component.UsingFactoryMethod((k, cm, c) => ctx.ToFactory(new FactoryContext { RequestedType = c.RequestedType, Arguments = c.HasAdditionalArguments ? c.AdditionalArguments.Values.Cast <object>().ToArray() : null }), true); } else if (context.ToFactoryResolver != null) { ServiceContext ctx = context; component = component.UsingFactoryMethod((k, cm, c) => ctx.ToFactoryResolver(new FactoryContext { RequestedType = c.RequestedType, Arguments = c.HasAdditionalArguments ? c.AdditionalArguments.Values.Cast <object>().ToArray() : null }, new WindsorResolver(k)), true); } else { component = component.ImplementedBy(context.To); } if (context.ComponentDependencies.Any()) { component = context.ComponentDependencies.Aggregate(component, (current, componentDependency) => current.DependsOn(Dependency.OnComponent(componentDependency.Key, componentDependency.Value))); } if (context.ValueDependencies.Any()) { component = context.ValueDependencies.Aggregate(component, (current, dependency) => current.DependsOn(Property.ForKey(dependency.Key).Eq(dependency.Value))); } var interceptors = new List <string>(); if (context.Interceptors.Any()) { var interceptorName = string.Format("interceptor_{0}_{1}", context.For.First().Name, Guid.NewGuid().ToString().Replace("-", string.Empty)); //Register interceptor itself by name container.Register(Component.For <RegistrationInterceptor>().Named(interceptorName) .DynamicParameters((k, c, p) => { p["context"] = c; return(null); }) .DependsOn( Dependency.OnValue("interceptions", context.Interceptors), Dependency.OnValue("container", container), Dependency.OnValue("context", null) ).LifestyleTransient() ); interceptors.Add(interceptorName); } if (context.InterceptorsByName.Any()) { interceptors.AddRange(context.InterceptorsByName); } if (interceptors.Any()) { component.Interceptors(interceptors.ToArray()); } if (!string.IsNullOrEmpty(context.Name)) { component = component.Named(context.Name); } component = component.ToWindsorLifeTime(context.Lifetime); container.Register(component); }
public override IRegistration RegisterInterceptors <S>(ComponentRegistration <S> registration) { return(registration.Interceptors(new InterceptorReference(typeof(TestInterceptor3))).Last .Interceptors(new InterceptorReference(typeof(TestInterceptor1))).First .Interceptors(new InterceptorReference(typeof(TestInterceptor2))).AtIndex(1)); }
public override IRegistration RegisterInterceptors <S>(ComponentRegistration <S> registration) { return(registration.Interceptors(typeof(TestInterceptor1), typeof(TestInterceptor2))); }
protected override IRegistration RegisterInterceptors <S>(ComponentRegistration <S> registration) { return(registration.Interceptors(new InterceptorReference(typeof(TestInterceptor1))).Anywhere); }
public override IRegistration RegisterInterceptors <S>(ComponentRegistration <S> registration) { return(registration.Interceptors( InterceptorReference.ForType(typeof(TestInterceptor1)), InterceptorReference.ForType(typeof(TestInterceptor2))).First); }
/// <summary> /// 增加Debug调试行为 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="componentRegistration">The component registration.</param> /// <returns></returns> public static ComponentRegistration <T> AddDebugBehavior <T>(this ComponentRegistration <T> componentRegistration) { return(componentRegistration.Interceptors(new InterceptorReference(typeof(DebugBehavior))).Anywhere); }
public override IRegistration RegisterInterceptors <S>(ComponentRegistration <S> registration) { return(registration.Interceptors <TestInterceptor1>().Interceptors <TestInterceptor2>()); }
private static ComponentRegistration <TFactory> AttachFactoryInterceptor <TFactory>(ComponentRegistration <TFactory> registration) where TFactory : class { return(registration.Interceptors(new InterceptorReference(TypedFactoryFacility.InterceptorKey)).Last); }
public override IRegistration RegisterInterceptors <S>(ComponentRegistration <S> registration) { return(registration.Interceptors("interceptorKey")); }
private void ConfigureInterceptors(ComponentRegistration obj) { var reg = obj.Interceptors(InterceptorReference.ForType <CacheInterceptor>()).First; }