2011-06-23 8 views
2

以下は私の設定です。私は、一致したメソッドへの呼び出しをインターセプトしたいと思います。マッチメソッドを追加するにはどうすればよいですか?一致するメソッドへの呼び出しをインターセプトする方法はありますか?

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

助けてください。

よろしくお願いいたします。

David

答えて

1

クラスMemberNameMatchingRuleには、いくつかのコンストラクタがあります。あなたが使用することをお勧めします

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

他のコンストラクタ:

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 
) 

あなたがIEnumerableをを渡す必要がある場合は、下記の記事読んで、従うことができ、次のいずれか を例えば、単一の方法についてHow to configure Unity to inject an array for IEnumerable

または、例えば、ワイルドカードを使用します。

<matchingRule name="rule2" type="MemberNameMatchingRule"> 
     <constructor> 
      <param name="nameToMatch" > 
      <value value="Method*"/> 
      </param> 
      <param name="ignoreCase" value="true"/> 
     </constructor> 
     </matchingRule> 
関連する問題