Using Interception without a decorator attribute?

Feb 23, 2010 at 8:14 PM

I'm pretty new to unity so forgive me if this is a silly question.

In David Hayden's webcast on unity and the interception extension (http://www.pnpguidance.net/Screencast/UnityInterceptionExtensionRemotingPolicyInjectorScreencastUnityTutorials.aspx), David created a custom attribute based on HandlerAttribute.   He then registered for  interception of  the interface with his handler (implementing ICallHandler) in the unity container.

Is it possible to do something similar without having to decorate the interface with a custom attribute?

I have a data contracts defined throughout my application, and would like to intercept all the methods decorated with the [ServiceOperation] attribute, without having to re-decorate them with an additional custom attribute.

Thanks.

 

 

Feb 24, 2010 at 5:02 AM

Of course. Define an interception policy, with matching rules that will match the methods you care about. Creating a custom HandlerAttribute is actually a more advanced scenario, and now how I'd expect this stuff to be used on a regular basis.

 

 

Feb 24, 2010 at 1:24 PM

Without a custom handler attribute, where do I place the logic I'd like to inject before the method executes?  Can you point me to a sample using injection in this way?

 

Thanks.

Feb 25, 2010 at 2:09 AM

The custom handler attribute does not contain the logic that executes before the method you want to intercept, that logic is in the custom handler.  In the screencast you watched, it is the StopWatchCallHandler class.  You'd still create the custom handler class but you need not create the custom handler attribute class since you don't want to decorate the interface with that attribute.  So as what Chris have said, you can configure your class to be intercepted by your custom handler by specifying matching rule(s) that will match the methods you want to be intercepted.  You can use either a MemberNameMatchingRule or a MethodSignatureMatchingRule.  For the example, refer to the documentation - http://msdn.microsoft.com/en-us/library/dd203208.aspx under the Streamlining Interception by Using PolicyDefinition API.  The documentation for the matching rules can also be found there, under the Key Scenarios -> Configuring and Using Matching Rules section.

 

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