相关疑难解决方法(0)

另一个组件中的MVC 6 RC2控制器

在MVC 6 RC1中,我们使用IAssemlbyProvider接口来注册在运行时发现的程序集并注入其他控制器类型,与此帖子类似.现在使用RC2版本IAssemblyProvider已被删除并已更改为(请参阅参考资料).

我们的框架版本目前net46.

自升级以来,我们在外部程序集(未引用)中的控制器返回404状态.

我们尝试通过手动将控制器添加到注册的控制器ApplicationPartManager.

var mvcBuilder = services.AddMvc();
var controllerFeature = new ControllerFeature();
mvcBuilder.PartManager.PopulateFeature(controllerFeature);

var moduleControllers = ModulesManager.GetControllers();
foreach (var c in moduleControllers)
    controllerFeature.Controllers.Add(c);

mvcBuilder.PartManager.PopulateFeature(controllerFeature);
Run Code Online (Sandbox Code Playgroud)

和...

services.AddMvc().ConfigureApplicationPartManager(app =>
{
    var controllerFeature = new ControllerFeature();
    app.PopulateFeature(controllerFeature);

    var moduleControllers = ModulesManager.GetControllers();
    foreach (var c in moduleControllers)
        controllerFeature.Controllers.Add(c);

    app.PopulateFeature(controllerFeature);
});
Run Code Online (Sandbox Code Playgroud)

现在,程序集肯定被加载到AppDomain我们的依赖注入系统中,为外部程序集中的其他项查找和填充服务.

通过我们之前的实现,这很好地使用了IAssemblyProvider.

public class ModuleAwareAssemblyProvider : IAssemblyProvider
{
    private readonly DefaultAssemblyProvider _defaultProvider;

    public …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc

9
推荐指数
1
解决办法
1515
查看次数

标签 统计

asp.net-core-mvc ×1

c# ×1