title: How do I work with Ninject in an ASP.NET MVC Web App?
body: <p>I've created a new MVC Web application and I have references to Ninject.dll, Ninject.Web.Common.dll and Ninject.Web.MVC.dll.</p>
  
  <p><strong>Global.asax.cs:</strong></p>
  
  <pre><code>public class MvcApplication : NinjectHttpApplication
      {
          public static void RegisterGlobalFilters(GlobalFilterCollection filters)
          {
              filters.Add(new HandleErrorAttribute());
          }
  
          public static void RegisterRoutes(RouteCollection routes)
          {
              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
              routes.MapRoute(
                  "Default", // Route name
                  "{controller}/{action}/{id}", // URL with parameters
                  new
                  {
                      controller = "Home",
                      action = "Index",
                      id = UrlParameter.Optional
                  });
          }
  
          protected override IKernel CreateKernel()
          {
              var kernel = new StandardKernel();
              kernel.Load(Assembly.GetExecutingAssembly());
              return kernel;
          }
  
          protected override void OnApplicationStarted()
          {
              base.OnApplicationStarted();
  
              AreaRegistration.RegisterAllAreas();
              RegisterGlobalFilters(GlobalFilters.Filters);
              RegisterRoutes(RouteTable.Routes);
          }
      }
  </code></pre>
  
  <p><strong>App_start\NinjectWebCommon:</strong></p>
  
  <pre><code>public static class NinjectWebCommon 
      {
          private static readonly Bootstrapper bootstrapper = new Bootstrapper();
  
          /// &lt;summary&gt;
          /// Starts the application
          /// &lt;/summary&gt;
          public static void Start() 
          {
              DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
              DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
              bootstrapper.Initialize(CreateKernel);
          }
  
          /// &lt;summary&gt;
          /// Stops the application.
          /// &lt;/summary&gt;
          public static void Stop()
          {
              bootstrapper.ShutDown();
          }
  
          /// &lt;summary&gt;
          /// Creates the kernel that will manage your application.
          /// &lt;/summary&gt;
          /// &lt;returns&gt;The created kernel.&lt;/returns&gt;
          private static IKernel CreateKernel()
          {
              var kernel = new StandardKernel();
              kernel.Bind&lt;Func&lt;IKernel&gt;&gt;().ToMethod(ctx =&gt; () =&gt; new Bootstrapper().Kernel);
              kernel.Bind&lt;IHttpModule&gt;().To&lt;HttpApplicationInitializationHttpModule&gt;();
  
              RegisterServices(kernel);
              return kernel;
          }
  
          /// &lt;summary&gt;
          /// Load your modules or register your services here!
          /// &lt;/summary&gt;
          /// &lt;param name="kernel"&gt;The kernel.&lt;/param&gt;
          private static void RegisterServices(IKernel kernel)
          {
          }        
      }
  </code></pre>
  
  <p>I get the error "The sequence contains no elements". What am I doing wrong?</p>
  
  <p>Error details:</p>
  
  <pre><code>Description: An unhandled exception occurred during the execution of the current web request. Examine the stack trace for more information about this error and where it originated in the code.
  
  Exception Details: System.InvalidOperationException: Sequence contains no elements
  
  Source Error:
    Unhandled exception occurred during execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
  
  
  Stack Trace:
  
  [InvalidOperationException: Последовательность не содержит элементов]
     System.Linq.Enumerable.Single(IEnumerable`1 source) +320
     Ninject.Web.Mvc.NinjectMvcHttpApplicationPlugin.Start() in c:\Projects\Ninject\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectMvcHttpApplicationPlugin.cs:53
     Ninject.Web.Common.Bootstrapper.&lt;Initialize&gt;b__0(INinjectHttpApplicationPlugin c) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs:52
     Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable`1 series, Action`1 action) in c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:32
     Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs:52
     Ninject.Web.Common.NinjectHttpApplication.Application_Start() in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\NinjectHttpApplication.cs:80
  </code></pre>