开发者

How to intercept the call to the matched method?

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

            </met开发者_如何学编程hod> 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


The class MemberNameMatchingRule has a few constructors. For example, for a single method:

<matchingRule name="rule1" type="MemberNameMatchingRule">
        <constructor>
          <param name="nameToMatch" >
            <value value="MethodA"/>
          </param>
        </constructor>
      </matchingRule>

Other constructors that you might want to use:

public MemberNameMatchingRule(
IEnumerable<MatchingInfo> matches
)
public MemberNameMatchingRule(
IEnumerable<string> namesToMatch
)
public MemberNameMatchingRule(
string nameToMatch
)
public MemberNameMatchingRule(
IEnumerable<string> namesToMatch,
bool ignoreCase
)
public MemberNameMatchingRule(
string nameToMatch,
bool ignoreCase
)

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:

<matchingRule name="rule2" type="MemberNameMatchingRule">
        <constructor>
          <param name="nameToMatch" >
            <value value="Method*"/>
          </param>
          <param name="ignoreCase" value="true"/>
        </constructor>
      </matchingRule>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜