how to plugin custom viewengine in MVC 6 beta7?

蓝咒 提交于 2019-12-07 01:37:00

问题


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?


回答1:


I figured it out, before calling

services.AddMvc()

I need to add my viewengine to DI

services.TryAddSingleton<IRazorViewEngine, MyCustomViewEngine>();


来源:https://stackoverflow.com/questions/32416007/how-to-plugin-custom-viewengine-in-mvc-6-beta7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!