How can I route an External Class Library in my Web API, ASP NET 5

后端 未结 1 1534
时光取名叫无心
时光取名叫无心 2021-01-29 13:00

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:

相关标签:
1条回答
  • 2021-01-29 13:06

    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:

    • 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

    (Source)

    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" };
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题