私はNinjectをテストしていますが、ハウツーに従えば、動作させることは不可能です。ウェブ上の情報はあまりにも厄介で、矛盾しています。私はVisual Studio 2012でMVC 4のウェブサイトを開発しており、Nugetを使ってNinjectをインストールしました。Ninject "このオブジェクトに対して定義されたパラメータのないコンストラクタはありません。"
"このオブジェクトに対して定義されたパラメータのないコンストラクタはありません。"というエラーが表示されます。私のコントローラに入るとすぐに。
私は必要なステップでした:
- Nugetインストール
- NinjectWebCommon.csでは、私はRegisterServices方法で私のインターフェイスを登録しました。私にHomeControllerで
私はこのように私のオブジェクトを設定します。
public ISurvey _survey { get; set; } [Inject] public HomeController(ISurvey s) { _survey = s; }
そして私は、次のエラーメッセージが出ます:だから私は、私が間違って何をしただろう
Server Error in '/' Application. No parameterless constructor defined for this object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.MissingMethodException: No parameterless constructor defined for this object. Source Error: An unhandled exception was generated during the 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: [MissingMethodException: No parameterless constructor defined for this object.] System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113 System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232 System.Activator.CreateInstance(Type type, Boolean nonPublic) +83 System.Activator.CreateInstance(Type type) +6 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +110 [InvalidOperationException: An error occurred when trying to create a controller of type 'Surveys.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.] System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +247 System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +438 System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +226 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +326 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +177 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +88 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +50 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
を? 4時間で、web.configファイルに問題があるか、参照がないか、工場が見つからない可能性があることがわかりました。今私は何をすべきか分からない。ご協力いただきありがとうございます。
NinjectWebCommon.csのコンテンツを追加できますか? – treze
ISurveyの実装内容を追加できますか?ところで、あなたはInject属性でコンストラクタを装飾する必要はありませんが、私はあなたの問題に関して何か違いがあるとは思わない。 – Hernan