Unity DI中的AutoMapper注册

3

我对Unity或StructureMap不是很熟悉。您如何将以下StructureMap注册示例转换为Unity注册语法?

    public class ConfigurationRegistry : Registry
    {
        public ConfigurationRegistry()
        {
            ForRequestedType<ConfigurationStore>()
                .CacheBy(InstanceScope.Singleton)
                .TheDefault.Is.OfConcreteType<ConfigurationStore>()
                .CtorDependency<IEnumerable<IObjectMapper>>().Is(expr => expr.ConstructedBy(MapperRegistry.AllMappers));

            ForRequestedType<IConfigurationProvider>()
                .TheDefault.Is.ConstructedBy(ctx => ctx.GetInstance<ConfigurationStore>());

            ForRequestedType<IConfiguration>()
                .TheDefault.Is.ConstructedBy(ctx => ctx.GetInstance<ConfigurationStore>());

            ForRequestedType<IMappingEngine>().TheDefaultIsConcreteType<MappingEngine>();

            ForRequestedType<ITypeMapFactory>().TheDefaultIsConcreteType<TypeMapFactory>();
        }
    }

你应该将你的解决方案放在答案中... - onof
1个回答

0

我想我明白了,如果我漏掉了什么,请告诉我。

Container
 .RegisterType<ConfigurationStore, ConfigurationStore>
                              (
                                 new ContainerControlledLifetimeManager()
                               , new InjectionConstructor(typeof(ITypeMapFactory)
                               , MapperRegistry.AllMappers())
                              )
 .RegisterType<IConfigurationProvider, ConfigurationStore>()
 .RegisterType<IConfiguration, ConfigurationStore>()
 .RegisterType<IMappingEngine, MappingEngine>()
 .RegisterType<ITypeMapFactory, TypeMapFactory>();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接