本文介绍了如何在MVC 6 beta7中插入自定义Viewengine?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在beta6中,我们能够插入这样的自定义视图引擎:
in beta6 we were able to plugin a custom viewengine like this:
services.AddMvc()
.AddViewOptions(options =>
{
options.ViewEngines.Clear();
options.ViewEngines.Add(typeof(MyCustomViewEngine));
});
此功能不再在beta7和options中起作用.ViewEngines似乎已更改为
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?);
如何在beta7中插入我自己的自定义Viewengine?
How can I plug in my own custom viewengine in beta7?
推荐答案
在调用
services.AddMvc()
我需要将Viewengine添加到DI
I need to add my viewengine to DI
services.TryAddSingleton<IRazorViewEngine, MyCustomViewEngine>();
这篇关于如何在MVC 6 beta7中插入自定义Viewengine?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!