How do I list Interceptors?

Dec 22, 2009 at 7:18 AM

Hi!

I've set my interceptors in the config file like:

 

<interceptor type="Microsoft.Practices.Unity.InterceptionExtension.TransparentProxyInterceptor, Microsoft.Practices.Unity.Interception" />
   <default type="MyProject.ObjectServices.IRepository`1, MyProject.ObjectServices"  />
   <key type="MyProject.ObjectServices.IUserRepository, MyProject.ObjectServices"  />

Now I wan't to write a test that verifies that the correct interceptors are set in my config, so I need a list of the interceptors?

Any hints`?

 

Dec 27, 2009 at 11:53 PM

That information isn't really tracked anywhere in a global list. Instead, interceptors are associated and looked up by the type they're intercepting.

You could write an extension that got a hold of the PolicyList object inside the container and then walk through it looking for ITypeInterceptorPolicy and IInstanceInterceptionPolicy objects. Actually, no, that won't work, IPolicyList isn't enumerable.

Kind of shut out on this one right now, sorry.

 

 

Jan 7, 2010 at 9:50 AM
Edited Jan 7, 2010 at 9:51 AM

Ok.. yes I tried to find some clues by looking at the tests in the unity source..

The best solution I have come up with soo far is to Resolve all objects that I expect to have a interceptor and iterate through them. I'm using TransparentProxyInterceptor so I can do:

var repositoryObject = unityContainer.Resolve(type);
Assert.That(RemotingServices.IsTransparentProxy(repositoryObject));

But that wouldn't work if I change to VirtualMethodInterceptor I think... so It's not a long lasting solution..