添加Web API和API文档到现有的MVC项目 [英] Adding Web API and API documentation to an existing MVC project

查看:466
本文介绍了添加Web API和API文档到现有的MVC项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地添加了一个网​​络API控制器到现有的 MVC4 应用程序。

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

我想有API文档的功能是新的Web API样品中可(例如http://sample.hostname.com/help)。我相信,这些使用 ApiExplorer 类。我试图仅仅复制 HelpPage 区域到我的项目,但我得到一个错误

I would like to have the api documentation functionality as is available in the new web api samples (ex. http://sample.hostname.com/help). I believe these use the ApiExplorer class. I tried just copying the HelpPage area into my project, but I get an error

String类型无法构造。您必须配置容器提供此值

"The type String cannot be constructed. You must configure the container to supply this value"

当我尝试导航帮助。

我必须做什么补充的API自动记录?

What must I do to add automated documentation of the API?

推荐答案

V5.2.2具有以下code:

V5.2.2 has the following code:

public HelpController()
        : this(GlobalConfiguration.Configuration)
    {
    }

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

在HelpController

in the HelpController

统一使用最参数的构造函数,所以要得到它的使用参数的构造函数,我改变了第二个重载受保护的:

Unity uses the constructor with the most arguments, so to get it to use the parameterless constructor I changed the second overload to protected:

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

和帮助页面都回

这篇关于添加Web API和API文档到现有的MVC项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆