Configuration problem for Interception

Nov 26, 2010 at 1:11 AM

I tried to test interception, but interception is not working.

I want to know what is wrong.

 

<configuration>
  <configSections>
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
  </configSections>

  <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration"/>

    <!--<namespace name="InterceptionTest"/>
    <assembly name="InterceptionTest"/>-->
   
    <container>     
      <extension type="Interception"/>
     
      <interception>
        <policy name="policy1">
          <callHandler name="handler1" type="InterceptionTest.LogCallHandler, InterceptionTest"/>
          <matchingRule name="rule1" type="NamespaceMatchingRule">
            <constructor>
              <param name="namespaceName" value="InterceptionTest.*"/>
            </constructor>
          </matchingRule>
        </policy>
      </interception>

      <register type="InterceptionTest.IIntercepted, InterceptionTest" mapTo="InterceptionTest.Intercepted, InterceptionTest">
        <interceptor type="VirtualMethodInterceptor"/>
        <policyInjection />
      </register>
     
    </container>
  </unity>
</configuration>

Nov 26, 2010 at 1:41 AM

Are you getting an exception when trying to load your container from the config?   The only problem I can see in  your config is the NamespaceMatchingRule type because it is not a full type name.  One more thing, make sure the methods you're trying to intercept are declared as virtual.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 26, 2010 at 3:06 AM

No exception when trying to load container from the config. The problem is that the object is not intercepted when I call the method.

The method is declared as virtual.

Nov 26, 2010 at 6:27 AM

I tried to repro it based on the information you've given but I didn't get the same result as yours, I get the expected interception.  If you could send a simple repro project, I could probably point out the problem.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 26, 2010 at 7:06 AM

I sent you the project. Please check it.

Nov 26, 2010 at 7:32 AM

I haven't received it.  Are you  using gmail?  Sometimes, we're unable to receive emails from gmail account with .zip attachments.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Dec 2, 2010 at 1:58 PM

The email I sent you was rejected, so I send you again.

 

Dec 2, 2010 at 10:29 PM
Edited Dec 2, 2010 at 10:51 PM

Got it.  The reasons why interception isn't happening on the repro you send are due to the Intercepted class not declared as public and the write method wasn't declared as virtual.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Dec 3, 2010 at 6:44 AM

Thanks for your help.

Simple mistake bothered me for a long time!!!