简体   繁体   English

温莎城堡拦截器管道

[英]Pipeline of Interceptor by castle windsor

I want to make a pipeline of Interceptors on a class named A. By pipleline i means each of those interceptor may do some processes before or after the class method invoked without calling the intercepted method directly, unlike traditional usage of interceptors in Windsor. 我想在名为A的类上建立一系列拦截器。通过pipleline,我表示每个拦截器都可以在调用类方法之前或之后进行某些处理,而无需直接调用被拦截的方法,这与Windsor中传统的拦截器用法不同。 Suppose the following example which I want to apply two interceptors Interceptor1 and Interceptor2 on all the class A methods. 假设下面的示例,我想在所有A类方法上应用两个拦截器Interceptor1和Interceptor2。 In futures others,maybe, other kind of interceptor will be added. 在期货中,也许会添加其他类型的拦截器。 provide that the order of these interceptors are not important, who should call the invocation.Proceed, where the intercepted method calling should happen. 前提是这些拦截器的顺序并不重要,应该由谁来调用调用。继续进行拦截方法的调用。

public class A
{
    public virtual void DoSomething()
    {

    }
}
public class Interceptor1 : IInterceptor
{
    public virtual void Intercept(IInvocation invocation)
    {

    }
}

public class Interceptor2 : IInterceptor
{
    public virtual void Intercept(IInvocation invocation)
    {

    }
}

As an example suppose we want to check security, start transaction or something like these before entring the a class method. 作为示例,假设我们要在输入类方法之前检查安全性,启动事务或类似的操作。 It should be mentioned that these interceptors are different for each class and might be changed during the development process. 应该提到的是,这些拦截器对于每个类都是不同的,并且在开发过程中可能会更改。 We can see such pattern in wcf where we use operation behavior or service behavior to have control over the entire service or each service operation. 我们可以在wcf中看到这种模式,其中我们使用操作行为或服务行为来控制整个服务或每个服务操作。

I must be an old school Castle guy, but isn't that what a Factory is for? 我一定是个守旧派的城堡人,但这不是工厂的目的吗? Slap an interface on each class, and let the factory work on that interface. 在每个类上添加一个接口,然后让工厂在该接口上工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM