我试图用unity 3.0.1304.1注册automapper 3.2.1。我尝试过StackOverflow的常用注册答案,没有运气。任何线索如何正确地注册最新的自动播放器?在最新版本中有什么变化吗?下面的代码和例外:
注册如下:
container.RegisterType<ConfigurationStore, ConfigurationStore>(new ContainerControlledLifetimeManager(), new InjectionConstructor(typeof(ITypeMapFactory), MapperRegistry.Mappers));
container.RegisterType<IConfigurationProvider, ConfigurationStore>();
container.RegisterType<IConfiguration, ConfigurationStore>();
container.RegisterType<IMappingEngine, MappingEngine>();
container.RegisterType<ITypeMapFactory, TypeMapFactory>();
然后我收到以下错误:
类型IDictionary`2没有可访问的构造函数。
当时正在解决这个问题:
Resolving AutoMapper.MappingEngine,(none) (mapped from AutoMapper.IMappingEngine, (none))
Resolving parameter "objectMapperCache" of constructor AutoMapper.MappingEngine(AutoMapper.IConfigurationProvider configurationProvider, AutoMapper.Internal.IDictionary`2[[AutoMapper.Impl.TypePair, AutoMapper, Version=3.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005],[AutoMapper.IObjectMapper, AutoMapper, Version=3.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005]] objectMapperCache, System.Func`2[[System.Type, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] serviceCtor)
Resolving AutoMapper.Internal.IDictionary`2[AutoMapper.Impl.TypePair,AutoMapper.IObjectMapper],(none)
答案 0 :(得分:2)
尝试在IMappingEngine注册中使用InjectionConstructor,如下所示:
container.RegisterType<IMappingEngine, MappingEngine>(new InjectionConstructor(typeof(IConfigurationProvider)));