Unity Interception and multiple mappings

Mar 29, 2010 at 3:52 PM

Hello !

I am use EntLib 4.1

My code:

	.RegisterType<IMyService, DataService>("Data")
	.RegisterType<IMyService, LoggingService>("Logging")
  .AddNewExtension<Interception>() .Configure<Interception>() .SetInterceptorFor<IMyService>(new TransparentProxyInterceptor()) .AddPolicy("servicePolicy") .AddCallHandler(typeof(StopwatchCallHandler)) .AddMatchingRule(new TypeMatchingRule(typeof(IMyService)));

var p = container.Resolve<IMyService>("Data");
p.MyMethod();//not interception, how necessary to do ?

Mar 29, 2010 at 5:16 PM

You need to specify the name for the registration on the SetInterceptorFor call:

.SetInterceptorFor<IMyService>("Data", new TransparentProxyInterceptor())

Or use "SetDefaultInterceptorFor" to intercept all registrations for this type regardless of name.


Mar 29, 2010 at 9:01 PM
Thanks! Next question: Why at addition .AddCallHandler (new LogCallHandler ()) from assembly Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers Interception does not work. How I am can use CallHandlers in unity ?? With my .AddCallHandler(typeof(StopwatchCallHandler)) all good work.
Mar 29, 2010 at 11:04 PM

Could you give more details than "does not work." Just no interception? Do you get an error message?

Also, have you added the Entlib extensions to your container?


Mar 30, 2010 at 8:12 AM
I have the customised logging block. My own handler StopwatchCallHandler - it is fine with it works (a code above). 
But I wish to use LogCallHandler () from assembly Microsoft. Practices. EnterpriseLibrary. PolicyInjection. CallHandlers.
For this purpose I change my code:

.RegisterType<IMyService, DataService>("Data")
.RegisterType<IMyService, LoggingService>("Logging")
.SetInterceptorFor<IMyService>(new TransparentProxyInterceptor())
.AddCallHandler(new LogCallHandler ())
.AddMatchingRule(new TypeMatchingRule(typeof(IMyService)));

var p = container.Resolve<IMyService>("Data");

As it is a pity that it does not work.
Prompt as correctly it to make?


Mar 30, 2010 at 10:11 AM

All is good. I have found my error. Thanks.