ASP.NET Web API binding with ninject

后端 未结 11 938
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:51

    if any anyone is still having problems, please listen for some reason ninject is not working how we would expect with mvc 4. In your web api, you need to write this code

    public DefaultController() : base() { }  
    

    This removes the error saying about no default constructor, then when you need to get your data from the get method write this code:

    public IEnumerable Get() 
    {
        return context.YourData;  
    } 
    

    Keep in mind, you will have to access your db class here as well, for instance:

    DefaultConnection context = new DefaultConnection(); 
    

提交回复
热议问题