The not-so-simple and (obviously) temporary solution for me was to create a background thread in NinjectWebCommon.RegisterServices
with the configuration I was debugging:
var thread = new System.Threading.Thread(() =>
{
while (!System.Diagnostics.Debugger.IsAttached)
{
System.Threading.Thread.Sleep(100);
}
// custom code, including kernel.Bind<>() calls here
});
thread.IsBackground = true;
thread.Start();
The idea here is to keep the thread you've created from executing the debuggable code until the debugger is actually attached. Setting the IsBackground
property is important, because this allows the rest of the RegisterServices
method to complete, which in turn allows the application to start and allows the debugger to attach.