I'm using Autofac.Extras.DynamicProxy2 to perform some method interception on a service implementation.
The service has quite a few methods and I only want to target a few.
Is there a better practice besides than checking for invocation target name against an approved string dictionary of methods I want to intercept?
public void Intercept(IInvocation invocation)
{
invocation.Proceed();
if (ContinueIntercept(invocation))
{
// Do intercept work
}
}
private bool ContinueIntercept(IInvocation invocation)
{
// Logic to compare invocation.MethodInvocationTarget.Name
}
It really doesn't add all that much over head, but it still feels like a poor way to do it. Especially since adding this to a specific service implementation means it will intercept all of the method calls of the base class common implementation. It wouldn't be as bad if it only intercepted the derived class.
I see that Castle.DynamicProxy2 has ways to specify invocation target, but I don't see how to wire that up with autofac.