Unity Interception IMatchRule invoked on every buildup

Feb 14, 2011 at 10:51 PM

Hi,

I have configured Interception using the following config

<container name="">
  <extension type="interception" />
  <interception>
    <policy name="LoggingPolicy">
      <matchingRule name="CallServiceMethods" type="..." />
      <callHandler name="LogHandler" type="..." />
    </policy>
  </interception>

  <register type="..." mapTo="...">
    <interceptor type="TransparentProxyInterceptor" />
    <policyInjection />
  </register>
</container>

I'm getting interception working, the call handler is being invoked when the matching rule identifies the correct candidates, but I'm noticing that the matching rule is being evaluated on every resolve,

The container is only being configured once during the application startup.

Is this expected behaviour or should the matching rules only be evaulated once as the build plan for the registered type is initially created ?

Have I configured interception correctly ?

 

Cheers...

Rob

 

Feb 14, 2011 at 11:13 PM

The matching rules will be evaluated on every resolve - they have to be, because we don't know at configuration time which types & methods will be matched by the rule. So we wait until you actually resolve something to check.

One could argue that the results of the matching rules should be cached after the first time to avoid repeated work. I actually tried that during the Unity 2.0 development and the cached solution was actually slower. Go figure. :-)

Feb 15, 2011 at 2:20 AM
Edited Feb 15, 2011 at 2:32 AM

Thanks for that... does that also mean the transparent proxy type is re-created for each resolve.

It might be worthwhile creating a persistent proxy on the fly, interrogating the matching rules at registration time (  I don't use parameter value matching, only method or namespaces ) and tweaking the registration maps.

I've done this to create dynamic WCF proxies around a ChannelFactory<T> instance

Feb 15, 2011 at 6:26 PM

No, the actual types are cached. The behaviors and call handlers, however, are wired each time.

Actually, we don't have to create Transparent proxy types - one proxy type works for everything we're intercepting.