Question

I'm learning to use Interceptor pattern with Ninject.

I have an interceptor as follows.

public class MyInterceptor:IInterceptor
{
    public void Intercept(IInvocation invocation)
    {
        Console.WriteLine("Pre Execute: " + invocation.Request.Method.Name);

        invocation.Proceed();

        Console.WriteLine("Post Execute: " + invocation.Request.Method.Name);
        Console.WriteLine("Returned: " + invocation.ReturnValue);
    }
}

I'm setting up my Ninject kernel in my Main Method as follows.

kernel = new StandardKernel();

kernel.Bind<MyClass>().ToSelf().Intercept().With(new MyInterceptor());
myClass = kernel.Get<MyClass>();

Issue is that, when debugging a method call to myClass, (I'm putting a break point on a statement like myClass.methodName() and pressing F11) there's a LOT of stack frames to pass, before I see the call to my Interceptor, and then to the actual method call.

I do realize that Ninject creates Dynamic Proxies .etc. behind the scenes, but this makes things a little harder, If I want to see the flow of my code, from all the interceptors to the actual methods. (Imagine debugging to see which interceptor is blocking a method call)

Is there a way to tell Visual Studio not to break on Ninject stack frames ? (I don't have Ninject source with me anyway)

UPDATE Essentially, What I want to do is tell VS that don't break on code that I don't have the source for...

Était-ce utile?

La solution

After digging around for 4 hours in the options dialog and searching Google for what certailn check boxes do (how complicated a single dialog can be made ?) I found the answer.

You can actually tell Visual Studio not to worry about certain DLLs or EXEs and step 'through' them without breaking and asking for source.

Here's how to do it.

  1. Open the options dialog in visual studio. (Tools > Options)
  2. Navigate to Debugging > Symbols section

Or type "Symbols" in the top right "Quick Launch" box in VS 2012+ and hit enter.

  1. At Bottom Right, Select 'All Modules Unless Excluded'

    ScreenCap http://i40.tinypic.com/10gaedt.png

  2. Click the link and specify the DLLs or EXEs you want to exclude.

  3. Add the modules that you don't care about don't want to debug.

ScreenCap

In my case, I had to add

  • Ninject.dll
    • Ninject Core DLL
  • Ninject.Extensions.Interception.dll
    • This is the Ninject Interception module
  • Ninject.Extensions.Interception.DynamicProxy.dll
    • I use the Dynamic Proxy implementation for interception module, instead of the LinFu implementation. I don't want to debug this either.

Essentially, this dialog means, 'I don't care about these DLLs. Just ignore them when I'm debugging'.

Seems like you need just the EXE or DLL name, and not the whole path. And it doesn't seem to be case-sensitive.

This option is in VS 2010 and VS 2012. If you have an older version and need this feature, you may be out of luck.

After adding this, All 'Step-Into' (F11) commands go only to the code I wrote, and doesn't ask for symbols, or ask me to locate a source files for Ninject. In the call stack window, all the stack frames from those assemblies are combined to one line named '[External Code]'.

Happy Coding.

I hope this made your life easier.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top