I'm trying to take a mock created by Rhino.Mocks and add an additional
interceptor, so that I can be notified of all calls to the mock.
I tried using reflection to add a second interceptor to the object,
using the following code:
private static void AddInterceptorTo(object mock)
{
FieldInfo interceptorsField = mock.GetType().GetField("__interceptors");
var interceptors = ((IInterceptor[])
interceptorsField.GetValue(mock)).ToList();
interceptors.Add(new Logger());
interceptorsField.SetValue(mock, __interceptors.ToArray());
}
It successfully added an interceptor to the __interceptors field in
the mock object, but this interceptor was never called. Examining the
DynamicProxy code, specifically
Castle.DynamicProxy.AbstractInvocation.Proceed, it looks like only one
interceptor can ever get called.
I also tried making my own proxy, passing two interceptor instances,
and only the first one got called:
new ProxyGenerator().CreateClassProxy<ClassToMock>(interceptorA, interceptorB);
Only interceptorA got called.
So my questions are:
Is it possible to add a second interceptor to a proxy object that was
already generated by Castle.DynamicProxy2?
Why am I able to pass two interceptors to CreateClassProxy? Since only
the first one seems to get called, what do the remaining ones do?
I don't really want the interceptors to be in parallel, they should
really be in series. Nested, like the classic Decorator pattern. Is
there a way to do this?
Alex
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---