c# - 添加了 Unity DI 框架,现在得到错误“UmbracoAuthorizeAttribute 类型有多个长度为 1 的构造函数。无法消除歧义。”
问题描述
我将 Unity DI 框架作为 nuget 包添加到我的 Umbraco 解决方案中。我的统一配置文件如下所示:
public static class UnityConfig
{
#region Unity Container
private static Lazy<IUnityContainer> container =
new Lazy<IUnityContainer>(() =>
{
var container = new UnityContainer();
RegisterTypes(container);
return container;
});
public static IUnityContainer Container => container.Value;
#endregion
public static void RegisterTypes(IUnityContainer container)
{
container.RegisterType<IHomeViewModelFactory, HomeViewModelFactory>(new PerResolveLifetimeManager());
}
}
我可以启动该网站,但是一旦我尝试访问 Umbraco 后台,我会得到:
UmbracoAuthorizeAttribute 类型有多个长度为 1 的构造函数。无法消除歧义。
更具体地说,日志文件说:
ERROR Umbraco.Core.UmbracoApplicationBase - An unhandled exception occurred
Unity.Exceptions.ResolutionFailedException: Resolution of the dependency failed, type = 'Umbraco.Web.Mvc.UmbracoAuthorizeAttribute', name = '(none)'.
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type UmbracoAuthorizeAttribute has multiple constructors of length 1. Unable to disambiguate.
-----------------------------------------------
At the time of the exception, the container was:
Resolving Umbraco.Web.Mvc.UmbracoAuthorizeAttribute,(none)
---> System.InvalidOperationException: The type UmbracoAuthorizeAttribute has multiple constructors of length 1. Unable to disambiguate.
at Unity.ObjectBuilder.BuildPlan.Selection.ConstructorSelectorPolicyBase`1.FindLongestConstructor(Type typeToConstruct)
at Unity.ObjectBuilder.BuildPlan.Selection.ConstructorSelectorPolicyBase`1.SelectConstructor(IBuilderContext context, IPolicyList resolverPolicyDestination)
at Unity.ObjectBuilder.BuildPlan.DynamicMethod.Creation.DynamicMethodConstructorStrategy.CreateInstanceBuildupExpression(DynamicBuildPlanGenerationContext buildContext, IBuilderContext context)
我该如何解决这个问题?
解决方案
尝试将此添加到统一配置
container.RegisterType<Name of Controller>(new InjectionConstructor());
推荐阅读
- go - 如何将接口切片更改为结构切片
- python - 安装pyaudio时如何解决这个错误?
- optaplanner - 在 optaplanner 中访问链位置或多实体子链?
- javascript - 如果我返回重定向(),laravel中的回声无法显示
- java - ViewPager内部片段返回父片段时不显示
- node.js - 从 EJS 调用 PUT 来表达
- python - 如何修复这个 python 刽子手游戏?
- java - Java for 循环索引:“j”不是在我的索引的一个循环之后从我的 char 数组的开头开始:“i”
- haskell - 简单的函数错误“变量不在范围内”haskell
- java - ModelMapper 无法将 java.util.List 转换为 java.util.List