c# – IKernel cannot find the assembly

Question:

I am starting to learn ASP.NET. After installing Ninject MVC3 and Ninject, the NinjectWebCommon.cs file appeared, but it contains errors related to IKernel:

"Could not find type or namespace name 'IKernel'. Missing using directive or assembly reference ?.

Accordingly, the project does not start. Unfortunately, a search on the Internet did not return any results. Please tell me where and what to add?

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(test_web.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(test_web.App_Start.NinjectWebCommon), "Stop")]
namespace test_web.App_Start
{
using System;
using System.Web;

using Microsoft.Web.Infrastructure.DynamicModuleHelper;

using Ninject;
using Ninject.Web.Common;

public static class NinjectWebCommon 
{
    private static readonly Bootstrapper bootstrapper = new Bootstrapper();

    /// <summary>
    /// Starts the application
    /// </summary>
    public static void Start() 
    {
        DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
        DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
        bootstrapper.Initialize(CreateKernel);
    }

    /// <summary>
    /// Stops the application.
    /// </summary>
    public static void Stop()
    {
        bootstrapper.ShutDown();
    }

    /// <summary>
    /// Creates the kernel that will manage your application.
    /// </summary>
    /// <returns>The created kernel.</returns>
    private static IKernel CreateKernel()
    {
        var kernel = new StandardKernel();
        try
        {
            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

            RegisterServices(kernel);
            return kernel;
        }
        catch
        {
            kernel.Dispose();
            throw;
        }
    }

    /// <summary>
    /// Load your modules or register your services here!
    /// </summary>
    /// <param name="kernel">The kernel.</param>
    private static void RegisterServices(IKernel kernel)
    {
    }        
  }

}

Answer:

If I understood correctly from this answer, then you eat at the same time use NinjectHttpApplication and App_Start you need to select one. To use Ninject read here

Scroll to Top