Normally I would register a custom view engine in the
RegisterRoutesclass like this:
System.Web.Mvc.ViewEngines.Engines.Insert(0,new MyViewEngine());
But because of the new .NET Core architecture, this isn't possible anymore.
To add a new view engine in .NET Core I found the following snippet, which has to be in the
Startup.csfile:
public void ConfigureServices(IServiceCollection services)
{
//register the MyViewLocationExpander into ViewLocationExpanders
services.Configure<RazorViewEngineOptions>(o => {
o.ViewLocationExpanders.Add(new MyViewLocationExpander());
});
// Add framework services.
services.AddMvc();
}
Because I want to add the view engine inside my Plugin, I tried to get the
IServiceCollectioninside my
RegisterRoutesclass. Unfortunately, this is not working (
IServiceCollectionis null).
Can anyone tell me where and how I can add the view engine?
Thanks for your help.