So I have an interceptor set up. But I don't want the debugger to bother with it - I want it to go straight from MyController to MyService when using 'step in' on _service.FooBar();
public class MyController : Controller
{
private readonly IMyService _service;
public MyController(IMyService srv) => _service = srv;
public void FooBar() => _service.FooBar();//I want the debugger to 'step in' from here...
}
public class MyService : IMyService
{
public void FooBar()
{
throw new NotImplementedException();//...to here
}
}
public static class NinjectWebCommon
{
...
private static void RegisterServices(IBindingRoot kernel)
{
var serviceAssembly = Assembly.GetAssembly(typeof(MyService));
kernel.Bind(x =>
{
x.From(serviceAssembly)
.SelectAllClasses().BindDefaultInterface()
.Configure(p => p.InRequestScope().Intercept().With<DatabaseTransactionInterceptor>());
});
}
public class DatabaseTransactionInterceptor : IInterceptor
{
private readonly IDBEngine _dbEngine;
public DatabaseTransactionInterceptor(IDBEngine dbEngine)
{
_dbEngine = dbEngine;
}
public void Intercept(IInvocation invocation)
{
var shouldTerminate = !invocation.ContainsAttribute<DoNotTerminateAttribute>();
try
{
invocation.Proceed();
if (shouldTerminate)
{
_dbEngine.Terminate();
}
}
catch
{
_dbEngine.Terminate(true);
throw;
}
}
}
internal static class NinjectInvocationExtensions
{
internal static bool ContainsAttribute<T>(this IInvocation invocation) where T : Attribute
{
var request = invocation.Request;
var wasCalledFromInterface = request.Method.DeclaringType != null;
return wasCalledFromInterface
? InterfaceRequestContainsAttribute<T>(request)
: ConcreteRequestContainsAttribute<T>(request);
}
...
private static MethodInfo GetDerivedMethod(Type derivedType, MethodInfo interfaceMethod) =>
derivedType.GetMethods()
.Single(derivedMethod => derivedMethod.IsEqualForOverloadResolution(interfaceMethod));
}
I managed partial success by adding a DebuggerStepThrough attribute to the DatabaseTransactionInterceptor class, but it still goes into NinjectInvocationExtensions.ContainsAttribute(). I tried adding the attribute to NinjectInvocationExtensions, but the debugger still goes into GetDerivedMethod().
Is there any way to accomplish what I want?