Brandon,
Try this code out. I have made it work just fine. Here is how I defined the classes:
public class Interceptor : SimpleInterceptor
{
protected override void BeforeInvoke(IInvocation invocation)
{
var invokedMethod = invocation.Request.Method;
if (invokedMethod.IsDefined(typeof(EmulateAttribute), true))
{
var methodParameters = invokedMethod.GetParameters();
for (int i = 0; i < methodParameters.Length; i++)
{
var param = methodParameters[i];
if (param.IsDefined(typeof (EmulatedUserAttribute), true))
{
invocation.Request.Arguments[i] = 5678;
}
}
}
}
}
public interface IIntercepted
{
[Emulate]
void InterceptedMethod([EmulatedUser] int userId);
}
public class Intercepted : IIntercepted
{
[Emulate]
public void InterceptedMethod([EmulatedUser] int userId)
{
Console.WriteLine("UserID: {0}", userId);
}
}
I am requesting an instance of IIntercepted
instead of Intercepted
. If I request the concrete class, the interception will not work. Maybe this can get you in the right path.
var kernel = new StandardKernel();
kernel.Bind<IIntercepted>().To<Intercepted>().Intercept().With<Interceptor>();
var target = kernel.Get<IIntercepted>();
target.InterceptedMethod(1234); // Outputs 5678