我怎样才能航线外部类库在我的Web API,ASP NET 5 [英] How can I route an External Class Library in my Web API, ASP NET 5

查看:83
本文介绍了我怎样才能航线外部类库在我的Web API,ASP NET 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP NET 5创造了一个WEB API和我可以引用外部类库vNext。
我工作的Visual Studio 2015年社区。
在图书馆我有这个控制器:

I have created an WEB API in ASP NET 5 and I can reference an external Class Library vNext. I am working on Visual Studio 2015 Community. In that Library I have this controller:

[Route("api/[controller]")]
public class NovosController : Controller
{
    // GET: api/values

    [HttpGet]
    public IEnumerable<string> Get()
    {
        return new string[] { "i am", "an external library" };
    }

要在我的网站API's引用添加这个库,我不得不浏览DLL的(一个用于dnxcore50,一个用于dnx451)。

To add this library in my Web API´s references I had to browse the DLL's (one for dnxcore50 and one for dnx451).

这是结果:

dnx451

在我的Web API,我可以从该控制器的数据,但我的不能从URL接取它。
但如果库在同一溶液I可以从URL接取它

In my web API I can get the data from that controller but I can't acess it from URL. But if the library is in the same Solution I can acess it from the URL.

例如:

如果外部库:

本地主机:51000 / API /诺沃斯

localhost:51000/api/novos

返回我什么

,但如果该库是在相同的溶液

but if the library is in the same solution:

本地主机:51000 / API /诺沃斯

localhost:51000/api/novos

返回我我是一个外部库

我想通过URL来接取到外部库,但我找不到任何解决我的问题,没有任何人知道如何使这件事情的?

I want to acess by URL to the external library but I can't find any solution to my problem, there is anyone that knows how to make this thing work?

推荐答案

您并不需要什么特别的允许由 IControllerTypeProvider 被发现,只要你的外部类库当你遵守要件:

You don't need anything special to allow your external class library to be discovered by IControllerTypeProvider as long as you comply with the requisites:


  • 必须是类

  • 不能是抽象

  • 已是公开的

  • 必须是顶级(未嵌套)

  • 不能通用

  • 有可能来自控制器后缀(波苏斯)Controller基类或结束派生和位于组装的引用MVC组装

  • has to be class
  • can’t be abstract
  • has to be public
  • has to be top-level (not nested)
  • can’t be generic
  • has to either derive from Controller base class or end in Controller suffix (for POCOs) and be located in an assembly that references MVC assembly

来源

在你的具体情况,我想你只需要删除路线注释,因为它没有看起来正确。

In your particular case, I think you just need to remove the Route annotation, since it doesn't looks right.

using Microsoft.AspNet.Mvc;
using System.Collections.Generic;

namespace External.Controllers
{
    [Route("api/[controller]")]
    public class NovosController: Controller
    {
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "I am", "an external library" };
        }
    }
}

这篇关于我怎样才能航线外部类库在我的Web API,ASP NET 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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