2013-10-18 3 views
2

Ninject.Web.Common 참조를 설치하기 위해 Nuget을 사용했습니다. ASP.net Web API (APIController)와 함께 문제없이 사용하지만 ASP.net MVC 4 (Controller)를 사용할 때 문제가 발생합니다.Ninject.Web.Common이 객체에 대해 정의 된 매개 변수없는 생성자가 없습니다.

오류 :

No parameterless constructor defined for this object. 

NinjectWebCommon.cs :

[assembly: WebActivator.PreApplicationStartMethod(typeof(CarsApp.Web.App_Start.NinjectWebCommon), "Start")] 
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(CarsApp.Web.App_Start.NinjectWebCommon), "Stop")] 

namespace CarsApp.Web.App_Start 
{ 
    using System; 
    using System.Web; 

    using Microsoft.Web.Infrastructure.DynamicModuleHelper; 

    using Ninject; 
    using Ninject.Web.Common; 
    //using App.WebUI.Infrastructure; 
    using App.Domain.Abstract; 
    using App.Domain.Concreate; 
    using System.Web.Http; 
    using App.Web.Infrastructure; 

    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(); 
      kernel.Bind<Func<IKernel>>().ToMethod(ctx =>() => new Bootstrapper().Kernel); 
      kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); 

      // Install our Ninject-based IDependencyResolver into the Web API config 
      GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel); 

      RegisterServices(kernel); 
      return kernel; 
     } 

     /// <summary> 
     /// Load your modules or register your services here! 
     /// </summary> 
     /// <param name="kernel">The kernel.</param> 
     private static void RegisterServices(IKernel kernel) 
     { 
      kernel.Bind<IMembershipRepository>().To<EFMembershipRepository>(); 
      kernel.Bind<IBranchRepository>().To<EFBranchRepository>(); 
     }   
    } 
} 
+1

화면의 오른쪽에 동일한 오류가있는 최소 7 개의 질문이 표시됩니다. 시도한 제안과 그 결과는 무엇인지 말해 줄 수 있습니까? –

답변

0

당신의 Web.config에 당신이 MVC에 대한 두 줄이있는 경우 설치 패키지 Ninject.MVC3

0

확인과 시도 버전 관리, 나는 비슷한 것을 가지고 있었다 :

<dependentAssembly> 
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
    </dependentAssembly> 
<dependentAssembly> 
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersion="4.0.0.0-4.0.0.1" newVersion="4.0.0.1" /> 
</dependentAssembly> 

그런 다음 당신이 4.0.0.1의 내 경우에 사용되는 가장 높은 버전으로 리디렉션, 같은 하나 개의 라인으로 대체 할 경우

<dependentAssembly> 
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" /> 
    </dependentAssembly> 

이 나를 위해 그것을했다.

0

MVC5를 사용하고 Install-Package Ninject.MVC5를 사용하여 내 문제를 해결했습니다.

관련 문제