ASP.NET Web API binding with ninject

后端 未结 11 978
Happy的楠姐
Happy的楠姐 2020-12-12 22:46

I have just installed the mvc4 rc update and I am trying to build an api application with little luck.

I am using ninject but cant get my controllers to load. I keep

11条回答
  •  醉话见心
    2020-12-12 22:53

    Hopefully this helps someone else...

    I was having the same issue and it was related to me moving class responsible for registering assembly in charge of initializing controllers. Moved out of web into framework project.

    Using Autofac but same would apply for other containers.

    Was calling:

    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
    

    Which works fine when it's within web application, but threw above exception when moved to framework project as the executing assembly no longer contains the controllers.

    Instead had to update to:

    builder.RegisterApiControllers(Assembly.GetCallingAssembly());
    

提交回复
热议问题