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

前端 未结 5 1826
一整个雨季
一整个雨季 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条回答
  •  猫巷女王i
    2020-12-01 06:58

    For .NET Core 3.0 the API has been slightly changed and the easiest way to register controllers from external assembly in Startup.cs looks like:

    public void ConfigureServices(IServiceCollection services)
    {
        var assembly = typeof(**AnyTypeFromRequiredAssembly**).Assembly;
    
        services.AddControllers()
            .PartManager.ApplicationParts.Add(new AssemblyPart(assembly));
    }
    

提交回复
热议问题