温莎城堡拦截器选择器和挂钩

发布于 2024-10-05 00:08:03 字数 1325 浏览 0 评论 0原文

我正在温莎城堡做一些项目,配置文件中的拦截器挂钩有一些问题 我创建了实现 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>

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

I'm doing some project in Castle Windsor and I have some problems with interceptor hook in config file
I created class that impements 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
}

All I want to do is to intercept methods whose name start with "Save" and hook them dynamically in the config file.
Also, in config file I have the following:

<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>

I suppose that I'm doing something wrong in config file.
Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文