Loading and registering API Controllers From Class Library in ASP.NET core

前端 未结 4 1832
梦谈多话
梦谈多话 2020-12-09 10:00

I am using ASP.NET Core 1.0.1. I have the following

  • A class library that uses \"Microsoft.AspNetCore.Mvc\": \"1.0.1\" in order to develo
4条回答
  •  清歌不尽
    2020-12-09 10:47

    https://curia.me/how-to-use-a-controller-from-another-assembly-in-asp-net-core/

    So, this is a more precise way to load a controller rather than the whole assembly.

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        ...
    
        services.AddMvc()
            .AddApplicationPart(typeof(Namespace.SubNamespace.ControllerName).Assembly);
    
        ...
    }
    

提交回复
热议问题