How to use a controller in another assembly in ASP.NET Core MVC 2.0?

前端 未结 5 1828
一整个雨季
一整个雨季 2020-12-01 06:16

For the sake of modularity, I have created some controllers in different assemblies. Each assembly represents a bounded context (a module, a sub-system, a division, etc.) of

5条回答
  •  情书的邮戳
    2020-12-01 07:01

    Inside the ConfigureServices method of the Startup class you have to call the following:

    services.AddMvc().AddApplicationPart(assembly).AddControllersAsServices();
    

    Where assembly is the instance Assembly representing Contoso.School.UserService.dll.

    You can load it either getting it from any included type or like this:

    var assembly = Assembly.Load("Contoso.School.UserService");
    

提交回复
热议问题