如何拦截对匹配方法的调用?
下面是我的配置,我想拦截对匹配方法的调用。我应该怎么做才能添加匹配方法?
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<sectionExtension
type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension,
Microsoft.Practices.Unity.Interception.Configuration" />
<alias alias="IDAL" type="InterceptionBlockApplication.IDAL,InterceptionBlockApplication"/>
<alias alias="DALTest" type="InterceptionBlockApplication.DALTest,InterceptionBlockApplication"/>
<container name="DALTest">
<extension type="Interception"/>
<interception>
<policy name="TestPolicy">
<matchingRule name="Method Signature Matching Rule" type="MemberNameMatchingRule">
<method name="MethodA"/>
<method name="MethodB">
</method> I try to do that. But it will throw a exception that:
[ Configuration is incorrect, the type Microsoft.Practices.Unity.InterceptionExtension.MemberNameMatchingRule does not have a method named MethodA that takes parameters named .]
What should I do?
</matchingRule>
<callHandler name="MyLogCallHandler" type="InterceptionBlockApplication.MyLogCallHandler, InterceptionBlockApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
</callHandler>
</policy>
</interception>
<register type="IDAL" mapTo="DALTest" name="DALTest">
<interceptor isDefaultForType="false" type="VirtualMethodInterceptor"/>
</register>
</container>
</unity>
任何帮助将不胜感激。
问候。
大卫
Below is my configuration, and I want to intercept the call to the matched method. What should I do to add the match methods?
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<sectionExtension
type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension,
Microsoft.Practices.Unity.Interception.Configuration" />
<alias alias="IDAL" type="InterceptionBlockApplication.IDAL,InterceptionBlockApplication"/>
<alias alias="DALTest" type="InterceptionBlockApplication.DALTest,InterceptionBlockApplication"/>
<container name="DALTest">
<extension type="Interception"/>
<interception>
<policy name="TestPolicy">
<matchingRule name="Method Signature Matching Rule" type="MemberNameMatchingRule">
<method name="MethodA"/>
<method name="MethodB">
</method> I try to do that. But it will throw a exception that:
[ Configuration is incorrect, the type Microsoft.Practices.Unity.InterceptionExtension.MemberNameMatchingRule does not have a method named MethodA that takes parameters named .]
What should I do?
</matchingRule>
<callHandler name="MyLogCallHandler" type="InterceptionBlockApplication.MyLogCallHandler, InterceptionBlockApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
</callHandler>
</policy>
</interception>
<register type="IDAL" mapTo="DALTest" name="DALTest">
<interceptor isDefaultForType="false" type="VirtualMethodInterceptor"/>
</register>
</container>
</unity>
Any help will be appreciate.
Regards.
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MemberNameMatchingRule 类有几个构造函数。例如,对于单个方法:
您可能想要使用的其他构造函数:
如果您需要传递 IEnumerable,您可以阅读并遵循以下文章:
如何配置 Unity 为 IEnumerable 注入数组
或者使用通配符,例如:
The class MemberNameMatchingRule has a few constructors. For example, for a single method:
Other constructors that you might want to use:
If you need to pass an IEnumerable, you can either read and follow the article below:
How to configure Unity to inject an array for IEnumerable
OR use a wildcard, for example: