我正在使用asp.net core 2.2开发模块化应用程序,并使用此代码加载具有自己的控制器和视图的外部程序集
foreach (var assembly in _moduleManager.Assemblies)
{
//Register controllers
mvcBuilder.AddApplicationPart(assembly);
}
然后用此代码使视图引擎选择视图的位置
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
//I have created junction folders for all apps and modules in Dios.Core.Web Apps and Modules folder so that the razor engine can get the view locations
var modulesViewLocations = new List<string>();
foreach (var module in _modules)
{
var folderName = module.ExtensionType == ExtensionTypes.App ? "Apps" : "Modules";
var locations = new string[]
{
"/" + folderName + "/" + module.Directory.Name + "/Views/{1}/{0}.cshtml",
"/" + folderName + "/" + module.Directory.Name + "/Views/Shared/{0}.cshtml"
};
modulesViewLocations.AddRange(locations);
}
return viewLocations.Concat(modulesViewLocations);
}
public void PopulateValues(ViewLocationExpanderContext context)
{
context.Values["extensionviewlocation"] = nameof(ExtensionViewLocationExpander);
}
然后使用
将它们添加到服务中 services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new ExtensionViewLocationExpander(_moduleManager.Modules));
options.AllowRecompilingViewsOnFileChange = true;
}
一切正常,除了当我更改外部程序集中的任何视图然后刷新浏览器没有任何反应时,我必须重新构建程序集才能感觉到更改
有什么帮助吗?