Castle Windsor Interceptor选择器和挂钩

时间:2010-12-01 09:42:22

标签: castle-windsor interceptor castle-dynamicproxy

我正在Castle Windsor做一些项目,我在配置文件中遇到拦截器钩子的问题 我创建了一个强制要求IProxyGenerationHook的课程:

public class LoggingProxyGenerationHook : IProxyGenerationHook
{

    #region IProxyGenerationHook Members

    public void MethodsInspected()
    {
        //throw new Exception("The method or operation is not implemented.");
    }

    public void NonVirtualMemberNotification(Type type, System.Reflection.MemberInfo memberInfo)
    {
        //throw new Exception("The method or operation is not implemented.");
    }

    public bool ShouldInterceptMethod(Type type, System.Reflection.MethodInfo methodInfo)
    {
        return methodInfo.Name.StartsWith("Save", StringComparison.Ordinal);
    }

    #endregion
}

我想要做的就是拦截名称以“Save”开头的方法,并在配置文件中动态挂钩它们。 另外,在配置文件中我有以下内容:

<component id="LoggingAspect" type="DynamicInterceptor.LoggingAspect, DynamicInterceptor"></component>
<component id="LoggingProxyGenerationHook" type="DynamicInterceptor.LoggingProxyGenerationHook, DynamicInterceptor"></component>
<component id="TestClass1" type="TestClasses.TestClass1, TestClasses">
<interceptors hook ="${LoggingProxyGenerationHook}">
<interceptor>${LoggingAspect}</interceptor>
</interceptors>
</component>

我想我在配置文件中做错了。 有什么想法吗?

1 个答案:

答案 0 :(得分:2)

Works for me.(Windsor / Core 2.5.2)