Adding Web API and API documentation to an existing MVC project

后端 未结 7 941
时光说笑
时光说笑 2021-02-14 03:01

I have successfully added a web api controller to an existing MVC4 application.

I would like to have the api documentation functionality as is

7条回答
  •  野的像风
    2021-02-14 03:44

    As others have already said, you must first install the NuGet package Microsoft.AspNet.WebApi.HelpPage. This will create a new HelpPage Area in your application with the views, models and controllers required to display the documentation.

    However, the HelpController that is generated contains an overloaded constructor:

    public HelpController(HttpConfiguration config)
    {
        Configuration = config;
    }
    

    This doesn't seem to play well with Unity (or probably any kind of DI container). You get this error:

    [InvalidOperationException: The type String cannot be constructed. You must configure the container to supply this value.]
    

    Remove this overload and it should work.

    Also just found another reference to this: http://www.stefan-scheller.com/2013/08/the-type-string-cannot-be-constructed-web-api-with-unity/

提交回复
热议问题