Unity Interception and multiple mappings

Mar 29, 2010 at 2:52 PM

Hello !

I am use EntLib 4.1

My code:

container
	.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 4: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 8: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 10: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 7: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:


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

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

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

 

Mar 30, 2010 at 9:11 AM

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