Ninject in ASP.NET MVC4

前端 未结 8 1941
终归单人心
终归单人心 2021-02-07 03:19

So after much screwing around I finally got Ninject wired in and compiling in my MVC4 application. The problem I was running into is the IDependencyScope interface no longer ex

8条回答
  •  生来不讨喜
    2021-02-07 04:02

    Ok after beating my head against the wall for far too long I figured out what was going on. The default project type for MVC4 running on .NET 4.5 had a reference to the original RC version of System.Web.Http instead of the updated version.

    Namespaces were missing, objects didn't exist, life was not good.

    Steps for resolution:

    1. Remove your reference to System.Web.Http in your MVC4 project
    2. Add Reference -> System.Web.Http
    3. Delete all work arounds you put in to get the old garbage version of System.Web.Http to work
    4. Reapply standard process to wire in Ninject.

      HOWEVER, the error of:

      Exception Details: Ninject.ActivationException: Error activating IntPtr No matching bindings are available, and the type is not self-bindable. Activation path: 3) Injection of dependency IntPtr into parameter method of constructor of type Func{IKernel} 2) Injection of dependency Func{IKernel} into parameter lazyKernel of constructor of type HttpApplicationInitializationHttpModule 1) Request for IHttpModule

      Suggestions: 1) Ensure that you have defined a binding for IntPtr. 2) If the binding was defined in a module, ensure that the module has been loaded into the kernel. 3) Ensure you have not accidentally created more than one kernel. 4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name. 5) If you are using automatic module loading, ensure the search path and filters are correct.

    Update This was solved by updating MVC from MVC4 Beta to MVC4 RC.

提交回复
热议问题