<legend id='HqgrX'><style id='HqgrX'><dir id='HqgrX'><q id='HqgrX'></q></dir></style></legend>

  • <i id='HqgrX'><tr id='HqgrX'><dt id='HqgrX'><q id='HqgrX'><span id='HqgrX'><b id='HqgrX'><form id='HqgrX'><ins id='HqgrX'></ins><ul id='HqgrX'></ul><sub id='HqgrX'></sub></form><legend id='HqgrX'></legend><bdo id='HqgrX'><pre id='HqgrX'><center id='HqgrX'></center></pre></bdo></b><th id='HqgrX'></th></span></q></dt></tr></i><div id='HqgrX'><tfoot id='HqgrX'></tfoot><dl id='HqgrX'><fieldset id='HqgrX'></fieldset></dl></div>

    <small id='HqgrX'></small><noframes id='HqgrX'>

    <tfoot id='HqgrX'></tfoot>

        <bdo id='HqgrX'></bdo><ul id='HqgrX'></ul>

        如何在 ASP.NET Core MVC 2.0 的另一个程序集中使用控制器?

        时间:2023-06-08
        <legend id='JHiA7'><style id='JHiA7'><dir id='JHiA7'><q id='JHiA7'></q></dir></style></legend>
          <tfoot id='JHiA7'></tfoot>

                  <bdo id='JHiA7'></bdo><ul id='JHiA7'></ul>
                • <small id='JHiA7'></small><noframes id='JHiA7'>

                • <i id='JHiA7'><tr id='JHiA7'><dt id='JHiA7'><q id='JHiA7'><span id='JHiA7'><b id='JHiA7'><form id='JHiA7'><ins id='JHiA7'></ins><ul id='JHiA7'></ul><sub id='JHiA7'></sub></form><legend id='JHiA7'></legend><bdo id='JHiA7'><pre id='JHiA7'><center id='JHiA7'></center></pre></bdo></b><th id='JHiA7'></th></span></q></dt></tr></i><div id='JHiA7'><tfoot id='JHiA7'></tfoot><dl id='JHiA7'><fieldset id='JHiA7'></fieldset></dl></div>

                    <tbody id='JHiA7'></tbody>

                  本文介绍了如何在 ASP.NET Core MVC 2.0 的另一个程序集中使用控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  为了模块化,我在不同的程序集中创建了一些控制器.每个程序集代表整个系统的一个有界上下文(一个模块、一个子系统、一个部门等).

                  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 the overall system.

                  每个模块的控制器都是由对其他模块一无所知的人开发的,中央编排器即将在一个应用程序中涵盖所有这些模块.

                  Each module's controllers are developed by someone that knows nothing about other modules, and a central orchestrator is about to cover all these modules in one single application.

                  所以,有一个名为 school 的模块,其中有一个 TeacherController.它的输出是 Contoso.School.UserService.dll.

                  So, there is this module called school, and it has a TeacherController in it. The output of it is Contoso.School.UserService.dll.

                  主编排器名为 Education,它引用了 Contoso.School.UserService.dll.

                  The main orchestrator is called Education and it has a reference to Contoso.School.UserService.dll.

                  我的 program.cs 是:

                      public static IWebHost BuildWebHost(string[] args) =>
                          WebHost.CreateDefaultBuilder(args).UseKestrel()
                              .UseStartup<Startup>()
                              .Build();
                  

                  但是对于教师控制器的路由,我得到 404.如何在其他程序集中使用控制器?

                  Yet for the routes of teacher controller, I get 404. How to use controllers in other assemblies?

                  推荐答案

                  Startup 类的 ConfigureServices 方法中,您必须调用以下代码:

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

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

                  其中 assembly 是代表 Contoso.School.UserService.dll 的实例 Assembly.

                  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");
                  

                  这篇关于如何在 ASP.NET Core MVC 2.0 的另一个程序集中使用控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MVC 6 Controller 中的 ControllerContext 和 ViewEngines 属性在哪里? 下一篇:如何在 ConfigureServices 中获取开发/暂存/生产托管环境

                  相关文章

                  <i id='wEaLq'><tr id='wEaLq'><dt id='wEaLq'><q id='wEaLq'><span id='wEaLq'><b id='wEaLq'><form id='wEaLq'><ins id='wEaLq'></ins><ul id='wEaLq'></ul><sub id='wEaLq'></sub></form><legend id='wEaLq'></legend><bdo id='wEaLq'><pre id='wEaLq'><center id='wEaLq'></center></pre></bdo></b><th id='wEaLq'></th></span></q></dt></tr></i><div id='wEaLq'><tfoot id='wEaLq'></tfoot><dl id='wEaLq'><fieldset id='wEaLq'></fieldset></dl></div>
                • <small id='wEaLq'></small><noframes id='wEaLq'>

                • <tfoot id='wEaLq'></tfoot><legend id='wEaLq'><style id='wEaLq'><dir id='wEaLq'><q id='wEaLq'></q></dir></style></legend>

                      • <bdo id='wEaLq'></bdo><ul id='wEaLq'></ul>