public void Register(IKernelInternal kernel) { // 1. Interceptor Registration kernel.Register( Component.For <LoggingInterceptor>() .ImplementedBy <LoggingInterceptor>()); // Another Interceptor registration. //kernel.Register( // Component.For<AnotherInterceptor>() // .ImplementedBy<AnotherInterceptor>()); // 2. Interceptor attached with Example Class. kernel.Register( Component.For <IExample>() .ImplementedBy <Example>() .Interceptors(InterceptorReference.ForType <LoggingInterceptor>()).Anywhere); // Mutiple Interceptors for the same class can be registered with one line as below. //kernel.Register( // Component.For<IExample>() // .ImplementedBy<Example>() // .Interceptors(new InterceptorReference[] { // InterceptorReference.ForType<LoggingInterceptor>(), // InterceptorReference.ForType<AnotherInterceptor>() // }).Anywhere); }
private void BuildControllers() { _container.Register(Component.For <DiscoveryController>() .ImplementedBy <DiscoveryController>() .Interceptors(InterceptorReference.ForKey("ConsoleInterceptor")).Anywhere .LifestyleTransient()); }
private void BuildProcessors() { _container.Register(Component.For <IEventProcessor>() .ImplementedBy <GenericEventProcessor>() .Interceptors(InterceptorReference.ForKey("ConsoleInterceptor")).Anywhere .LifestyleSingleton()); }
public void Setup() { var supplier = TestSupplier.CreateNaked(session); supplier.CreateSampleCore(session); client = TestClient.CreateNaked(session); address = client.CreateAddress(); user = client.Users.First(); session.Save(address); ServiceContext.GetUserName = () => user.Login; var container = new WindsorContainer(); container.AddComponent("RepositoryInterceptor", typeof(RepositoryInterceptor)); container.AddComponent("OfferRepository", typeof(IOfferRepository), typeof(OfferRepository)); container.AddComponent("Repository", typeof(IRepository <>), typeof(Repository <>)); var holder = new SessionFactoryHolder(); holder .Configuration .AddInputStream(HbmSerializer.Default.Serialize(Assembly.Load("Common.Models"))); container.Kernel.AddComponentInstance <ISessionFactoryHolder>(holder); IoC.Initialize(container); IoC.Container.Register( Component.For <IInforoomOnlineService>() .ImplementedBy <InforoomOnlineService>() .Interceptors(InterceptorReference.ForType <ContextLoaderInterceptor>()) .Anywhere, Component.For <ContextLoaderInterceptor>(), Component.For <IClientLoader>().ImplementedBy <ClientLoader>()); service = IoC.Resolve <IInforoomOnlineService>(); }
/// <summary> /// Registers a dynamic proxy on the end of each chain of responsibility to automatically /// handle the "unhandled request" scenario. /// </summary> /// <remarks>This method may be made obsolete by Castle Windsor 3.x's "IsDefault" feature on component registrations.</remarks> public void FinalizeChains() { if (_isFinalized) { throw new InvalidOperationException("Chains have already been finalized."); } // Prepare the interceptor for boilerplate to provide boilerplate "ProcessRequest" method invocation from arguments Kernel.Register(Component.For <ChainOfResponsibilityLinkInterceptor>()); var linkInterceptorReference = new InterceptorReference(typeof(ChainOfResponsibilityLinkInterceptor)); // Add interceptor to all implementation classes to handle boilerplate invocation foreach (var kvp in _chainTerminatingProxyByInterface) { var handlers = Kernel.GetHandlers(kvp.Key); foreach (var handler in handlers) { handler.ComponentModel.Interceptors.AddFirst(linkInterceptorReference); } // Register the chain terminating proxy Kernel.Register( Component.For(kvp.Key) .Instance(kvp.Value)); } _isFinalized = true; }
public void ProcessModel(IKernel kernel, ComponentModel model) { if (model.Services.Any(s => s == typeof(IServiceDependency))) { model.Interceptors.Add(InterceptorReference.ForType <UoWInterceptor>()); } }
public void TestInitialize() { windsorContainer = new WindsorContainer() .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero) .Register( Component.For <ServiceHostListener>(), Component.For <LoggingInterceptor>(), Component.For <CallCountServiceBehavior>(), Component.For <UnitOfworkEndPointBehavior>(), Component.For <NetDataContractFormatBehavior>(), Component.For <IOperations>().ImplementedBy <Operations>() .Named("Operations") .Interceptors(InterceptorReference.ForType <LoggingInterceptor>()).Anywhere .DependsOn(new { number = 42 }) .AsWcfService(new DefaultServiceModel().AddEndpoints( WcfEndpoint.BoundTo(new NetTcpBinding { PortSharingEnabled = true }) .At("net.tcp://localhost/Operations") ) ) ); LoggingInterceptor.Calls.Clear(); CallCountServiceBehavior.CallCount = 0; client = ChannelFactory <IOperations> .CreateChannel( new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations")); }
public void ProcessModel(IKernel kernel, ComponentModel model) { if (model.Services.Any(s => s == typeof(IEventAppService))) { model.Interceptors.Add(InterceptorReference.ForType <MongoEventInterceptor>()); } }
private void BuildServiceAgents() { _container.Register(Component.For <IDeviceStoreService>() .Instance(new ServiceProxyFactory() .CreateServiceProxy <IDeviceStoreService>( new Uri("fabric:/Microsoft.SupplyChain.Cloud.Administration/DeviceStoreService"))) .LifestyleSingleton() .Interceptors(InterceptorReference.ForKey("ConsoleInterceptor")) .Anywhere); _container.Register(Component.For <ISmartContractStoreService>() .Instance(new ServiceProxyFactory() .CreateServiceProxy <ISmartContractStoreService>( new Uri("fabric:/Microsoft.SupplyChain.Cloud.Administration/SmartContractStoreService"))) .LifestyleSingleton() .Interceptors(InterceptorReference.ForKey("ConsoleInterceptor")) .Anywhere); _container.Register(Component.For <IDeviceStoreServiceAgent>() .ImplementedBy <DeviceStoreServiceAgent>() .Interceptors(InterceptorReference.ForKey("ConsoleInterceptor")).Anywhere .LifestyleTransient()); _container.Register(Component.For <ISmartContractStoreServiceAgent>() .ImplementedBy <SmartContractStoreServiceAgent>() .Interceptors(InterceptorReference.ForKey("ConsoleInterceptor")).Anywhere .LifestyleTransient()); }
public void SetUp() { windsorContainer = new WindsorContainer() .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero) .Register( Component.For <ServiceHostListener>(), Component.For <CollectingInterceptor>(), Component.For <UnitOfworkEndPointBehavior>(), Component.For <NetDataContractFormatBehavior>(), Component.For <IOne>().ImplementedBy <One>().LifeStyle.PerWcfSession() .Interceptors(InterceptorReference.ForType <CollectingInterceptor>()).Anywhere, Component.For <ITwo>().ImplementedBy <Two>().LifestylePerWcfSession() .Interceptors(InterceptorReference.ForType <CollectingInterceptor>()).Anywhere, Component.For <IServiceWithSession>().ImplementedBy <ServiceWithSession>().LifeStyle.Transient .Named("Operations") .AsWcfService(new DefaultServiceModel().AddEndpoints( WcfEndpoint.BoundTo(new NetTcpBinding { PortSharingEnabled = true }) .At("net.tcp://localhost/Operations") ) ) ); client = CreateClient(); }
protected virtual void CollectFromConfiguration(ComponentModel model) { if (model.Configuration == null) { return; } IConfiguration interceptors = model.Configuration.Children["interceptors"]; if (interceptors == null) { return; } foreach (IConfiguration interceptor in interceptors.Children) { String value = interceptor.Value; if (!ReferenceExpressionUtil.IsReference(value)) { String message = String.Format( "The value for the interceptor must be a reference " + "to a component (Currently {0})", value); throw new ConfigurationException(message); } InterceptorReference interceptorRef = new InterceptorReference(ReferenceExpressionUtil.ExtractComponentKey(value)); model.Interceptors.Add(interceptorRef); model.Dependencies.Add(CreateDependencyModel(interceptorRef)); } }
static void Main(string[] args) { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For(typeof(WcfProxyInterceptor <IService1>))); container.Register(Component.For(typeof(IFoo)).ImplementedBy(typeof(Foo))); container.Register(Component.For(typeof(IBar)).ImplementedBy(typeof(Bar))); container.Register(Component.For <IService1>().Interceptors(InterceptorReference.ForType <WcfProxyInterceptor <IService1> >()).Anywhere); var test = (IFoo)container.Resolve(typeof(IFoo)); test.Do(); test.Do(); test.Do(); test.Do(); test.Do(); var testBar = (IBar)container.Resolve(typeof(IBar)); testBar.Do(); Console.ReadLine(); }
private void OnComponentRegistered(string key, IHandler handler) { AnyInterceptorAttribute anyInterceptorAttribute = null; bool isAnyIterceptor = handler.ComponentModel.Implementation.GetInterfaces().Any(i => { return(i.GetCustomAttributes(true).Any(a => { if (a is AnyInterceptorAttribute) { anyInterceptorAttribute = a as AnyInterceptorAttribute; return true; } return false; })); }); if (isAnyIterceptor && anyInterceptorAttribute != null && !string.IsNullOrWhiteSpace(anyInterceptorAttribute.InterceptorName)) { if (handler.ComponentModel.Interceptors.Count <= 0 || !handler.ComponentModel.Interceptors.Any(i => i.ToString().Equals(anyInterceptorAttribute.InterceptorName, StringComparison.OrdinalIgnoreCase))) { handler.ComponentModel.Interceptors.Add(InterceptorReference.ForKey(anyInterceptorAttribute.InterceptorName)); } } }
public void ApplyInterceptor(ComponentModel model) { if (!model.HasInterceptors && CanIntercept(model).Any()) { Validate(model); model.Interceptors.AddIfNotInCollection(InterceptorReference.ForType(typeof(TInterceptor))); } }
public override IEnumerable <InterceptorReference> GetExpectedInterceptorsInCorrectOrder() { yield return(InterceptorReference.ForType <TestInterceptor1>()); yield return(InterceptorReference.ForType <TestInterceptor2>()); yield return(InterceptorReference.ForType <TestInterceptor3>()); }
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 RegisterServices() { _container.Register(Classes.FromAssembly(typeof(IBlogPostService).Assembly) .Where(type => type.Name.EndsWith("Service")) .WithServiceDefaultInterfaces() .Configure(g => g.Interceptors(InterceptorReference.ForType <UnitOfWorkInterceptor>()) .First.LifestyleTransient()) .LifestyleTransient()); }
public override void Initialize() { this.Container.RegisterIfNot <DomainServiceInterceptor>(DependencyLifeStyle.Transient); this.Container.RegisterAssembly <IDomainService>(Assembly.GetAssembly(this.GetType()), configurer => { _ = configurer.Named(configurer.Implementation.Name); _ = configurer.Interceptors(InterceptorReference.ForType <DomainServiceInterceptor>()).Anywhere; }); }
private void Kernel_ComponentModelCreated(ComponentModel model) { var aspectValidator = new AspectValidatorBuilder(_aspectConfiguration).Build(); if (aspectValidator.Validate(model.Implementation, false) || model.Services.Any(x => aspectValidator.Validate(x, true))) { model.Interceptors.AddIfNotInCollection(InterceptorReference.ForType <AspectCoreInterceptor>()); } }
public void ProcessModel(IKernel kernel, ComponentModel model) { var cachedMethods = model.Implementation.GetMethods().Where(m => AttributesUtil.GetAttribute <LoggingAttribute>(m) != null).ToList(); if (cachedMethods.Any()) { model.Interceptors.AddIfNotInCollection(InterceptorReference.ForType <LoggingInterceptor>()); } }
public void Register(IKernelInternal kernel) { kernel.Register(Component.For <LoggingInterceptor>().ImplementedBy <LoggingInterceptor>()); kernel.Register( Component.For <ITask>().ImplementedBy <Task>().Interceptors( InterceptorReference.ForType <LoggingInterceptor>()).Anywhere); //Anywhere tells the registration process that this interceptor could be attached anywhere. }
public void should_be_able_to_show_that_interceptor_was_called_when_wcf_service_is_invoked() { ServiceDebugBehavior returnFaults = new ServiceDebugBehavior(); returnFaults.IncludeExceptionDetailInFaults = true; returnFaults.HttpHelpPageEnabled = true; ServiceMetadataBehavior metadata = new ServiceMetadataBehavior(); metadata.HttpGetEnabled = true; using ( new WindsorContainer() .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero) .Register( Component.For <TestInterceptor>(), // The interceptor must be registered like this. Component.For <IServiceBehavior>().Instance(returnFaults), Component.For <IServiceBehavior>().Instance(metadata), Component .For <IOperations>() .ImplementedBy <Operations>() .Interceptors(InterceptorReference.ForType <TestInterceptor>()).Anywhere // Don't care what order this is called in (and there is only one interceptor on this any case). .DependsOn(new { value = Expected }) // Notice how this constant is injected in to the service. .AsWcfService( new DefaultServiceModel() //.OpenEagerly() // This is useful to force immediate creation of services and to see any errors that may result. .AddBaseAddresses(BaseAddress) .AddEndpoints( WcfEndpoint .ForContract <IOperations>() .BoundTo(new WSHttpBinding()) .At(RelativeAddress) ) ))) { // This sleep is useful if/when you'd like to browse to http://localhost:8000/Operations.svc // to verify that meta-data is being published for this service. //Thread.Sleep(100000); // Notice that we're using the standard WCF channel factory here, // rather than the castle proxies. IOperations client = ChannelFactory <IOperations> .CreateChannel( new WSHttpBinding(), new EndpointAddress(BaseAddress + "/" + RelativeAddress) ); int result = client.GetValueFromConstructor(); Assert.AreEqual(Expected, result); Assert.That(TestInterceptor.mostRecentMethodCallIntercepoted, Is.EqualTo("GetValueFromConstructor")); } }
public void ProcessModel(IKernel kernel, ComponentModel model) { var cachedMethods = model.Implementation.GetMethods().Where(m => m.GetAttribute <CachedAttribute>() != null).ToList(); if (cachedMethods.Any()) { cachedMethods.CheckThatMethodsAreVirtual(); model.Interceptors.AddIfNotInCollection(InterceptorReference.ForType <CacheInterceptor>()); } }
protected override void Init() { Kernel.Register(Component.For <ProfilingInterceptor>().LifeStyle.PerThread); Kernel.ComponentModelCreated += model => { if (model.Implementation != typeof(ProfilingInterceptor)) { model.Interceptors.AddFirst(InterceptorReference.ForType <ProfilingInterceptor>()); } }; }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register( Component.For <IMessageQueueService>() .ImplementedBy <MessageQueueService>() .LifestyleTransient() .Interceptors(InterceptorReference.ForKey("LogAspect")).First .Interceptors(InterceptorReference.ForKey("EFDBEntityValidationExceptionAspect")).Anywhere, Component.For <IMessageQueueServiceFactory>().AsFactory()); }
public void Register(IKernelInternal kernel) { kernel.Register( Component.For <MethodLoggerInterceptor>() .ImplementedBy <MethodLoggerInterceptor>()); kernel.Register( Component.For <IPdfDocumentBuilder>() .ImplementedBy <PdfDocumentBuilder>() .Interceptors(InterceptorReference.ForType <MethodLoggerInterceptor>()).Anywhere); }
public void Install(IWindsorContainer container, IConfigurationStore store) => container.Register( Component.For <IInterceptor>() .ImplementedBy <ErrorHandlerInterceptor>() .Named("XInterceptor"), Component.For <IBeanCounter>() .ImplementedBy <BeanCounter>() .Interceptors( InterceptorReference.ForKey("XInterceptor")).Anywhere, Component.For <TextWriter>().Instance(_logWriter));
private void Kernel_ComponentModelCreated(ComponentModel model) { if ( !(model.Implementation.GetProperties() .Any(prop => prop.PropertyType.GetInterfaces().Contains(typeof(ILogger))) || model.Implementation.GetFields() .Any(l => l.FieldType.GetInterfaces().Contains(typeof(ILogger))))) { model.Interceptors.AddIfNotInCollection(InterceptorReference.ForType <AspectLogger>()); } }
public void Register(IKernelInternal kernel) { kernel.Register( Component.For <LoggingInterceptor>() .ImplementedBy <LoggingInterceptor>()); kernel.Register( Component.For <IRocket>() .ImplementedBy <Rocket>() .Interceptors(InterceptorReference.ForType <LoggingInterceptor>()).Anywhere); }
public void Register(IKernelInternal kernel) { kernel.Register( Component.For <TestInterceptor>() .ImplementedBy <TestInterceptor>()); kernel.Register( Component.For <OrderLogic>() .ImplementedBy <OrderLogic>() .Interceptors(InterceptorReference.ForType <TestInterceptor>()).Anywhere); }