为了账号安全,请及时绑定邮箱和手机立即绑定

添加了 Unity DI 框架,现在出现错误“类型

添加了 Unity DI 框架,现在出现错误“类型

C#
小怪兽爱吃肉 2021-07-09 16:11:05
我将 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 occurredUnity.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)我该如何解决这个问题?
查看完整描述

2 回答

?
森栏

TA贡献1810条经验 获得超5个赞

尝试将此添加到统一配置

container.RegisterType<Name of Controller>(new InjectionConstructor());


查看完整回答
反对 回复 2021-07-11
  • 2 回答
  • 0 关注
  • 296 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信