I would like to be able to use strongly-typed Razor views with models and controllers loaded at runtime. The assemblies are loaded during application startup in ConfigureServices
via anIApplicationFeatureProvider
.
services.AddMvc()
.ConfigureApplicationPartManager(apm => apm.FeatureProviders.Add(new DynamicControllerFeatureProvider()));
Views with a model type of dynamic
will compile just fine, but any strongly typed Razor views do not compile.
The type or namespace name 'TestModules' does not exist in the namespace 'TestProject' (are you missing an assembly reference?)
How can I make the Razor engine aware of the dynamically loaded assemblies so I can use strongly typed views? It seems like using a custom RazorBuildProvider
would work, but is there a better aproach?