Tag: #autheatpper autofac

使用AutoMapper 4.2和Autofac无法解析AutoMapper.IMapper

我尝试过各种各样的排列,但我目前的配置(因为它与AutoMapper有关)是这样的: builder.RegisterAssemblyTypes().AssignableTo(typeof(Profile)).As(); builder.Register(c => new MapperConfiguration(cfg => { foreach (var profile in c.Resolve<IEnumerable>()) { cfg.AddProfile(profile); } })).AsSelf().SingleInstance(); builder.Register(c => c.Resolve().CreateMapper(c.Resolve)).As().InstancePerLifetimeScope(); builder.RegisterType().As(); 我有一个使用IMapper mapper的构造函数,但是我继续得到YSOD: None of the constructors found with’Autofac.Core.Activators.Reflection.DefaultConstructorFinder’ on type ” can be invoked with the available services and parameters: Cannot resolve parameter ‘AutoMapper.IMapper mapper’ of constructor ‘Void .ctor(…,…,…, AutoMapper.IMapper)’. 这个类在没有automapper引用的情况下工作得很好,所以我确定麻烦在于我的automapper配置。 我不确定我在这里缺少什么,因为我对AutoFac和AutoMapper都很陌生。 编辑: 我也尝试过: […]