most of you will have certainly put the views as embedded resources
this is because File Providers do not behave as we would expect
context.Services.Configure<RazorViewEngineOptions>(options =>
{
options.FileProviders.Insert(/*...*/);
});usually if we do not use the Embedded type but we use the normal one (assemby)
the compiler will create 2 .dll files, the first package.dll and the second pakage.Views.dll
the problem arises exactly here, the default FileProvider or ApplicationPart for some reason can not handle the CompiledRazorAssemblyApplicationPart
clashing with this problem and doing some reverse ingeniering I discovered how does the non-modular aplication to load the Vews.dll
if (File.Exists(ViewAssembypath))
{
services.AddMvc().ConfigureApplicationPartManager(apm =>
{
foreach (var b in new CompiledRazorAssemblyApplicationPartFactory().GetApplicationParts(AssemblyLoadContext.Default.LoadFromAssemblyPath(ViewAssembypath)))
apm.ApplicationParts.Add(b);
});
}
else
throw new Exception("PluginsManager: no Plugin View Assembly found: " + ViewAssembypath);if you are working on something like this, I leave the link of my library to correctly manage the modules for a modular mvc project
it is really simple to use it and above all to customize all the work phase of the pacchatto, or if you turn take a cue from my solution ;)
a small example of how it works:
using AUR.NETCore.Mvc.PluginsManager;PluginsManager PM = new PluginsManager<interfaces.IPluginBase>("absolutePath of plugin folder");const string PluginFolder = "Plugins";
static PluginsManager<interfaces.IPluginBase> _Plugins;
public static PluginsManager<interfaces.IPluginBase> Plugins {
get {
if (_Plugins == null)
_Plugins = new PluginsManager<interfaces.IPluginBase>(Path.Combine(AppContext.BaseDirectory, PluginFolder));
return _Plugins;
}
}public void ConfigureServices(IServiceCollection services)
{
//...
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
Plugins.Load(services); // last row
}public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
//....
Plugins.Configure(app, env); // before default route
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}on github you find everything you need to use it to the fullest