Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to plugin custom viewengine in MVC 6 beta7?

in beta6 we were able to plugin a custom viewengine like this:

services.AddMvc()
.AddViewOptions(options =>
 {
     options.ViewEngines.Clear();
     options.ViewEngines.Add(typeof(MyCustomViewEngine));

 });

this no longer works in beta7 and options.ViewEngines seems to have changed to an

IList<IViewEngine>

I don't understand how to plug one in without having to new it up and provide its dependencies

options.ViewEngines.Add(new it up here?);

How can I plug in my own custom viewengine in beta7?

like image 262
Joe Audette Avatar asked Sep 05 '15 17:09

Joe Audette


1 Answers

I figured it out, before calling

services.AddMvc()

I need to add my viewengine to DI

services.TryAddSingleton<IRazorViewEngine, MyCustomViewEngine>();
like image 131
Joe Audette Avatar answered Oct 14 '22 07:10

Joe Audette