作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 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());
关于c# - 添加Unity DI框架,现在报错 "The type UmbracoAuthorizeAttribute has multiple constructors of length 1. Unable to disambiguate.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50592542/
我将 Unity DI 框架作为 nuget 包添加到我的 Umbraco 解决方案中。我的统一配置文件如下所示: public static class UnityConfig { #reg
我是一名优秀的程序员,十分优秀!