本文介绍了AutoMapper登记团结DI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我没那么熟悉统一或StructureMap。你如何转换以下StructureMap登记样品放入统一登记语法
公共类ConfigurationRegistry:注册
{
公共ConfigurationRegistry()
{
ForRequestedType< ConfigurationStore>()
.CacheBy(InstanceScope.Singleton)
.TheDefault.Is.OfConcreteType< ConfigurationStore>()
.CtorDependency<&IEnumerable的LT; IObjectMapper>方式>()是(表达式=> expr.ConstructedBy(MapperRegistry.AllMappers));
ForRequestedType&所述; IConfigurationProvider>()
.TheDefault.Is.ConstructedBy(CTX = GT; ctx.GetInstance&下; ConfigurationStore>());
ForRequestedType&所述; IConfiguration>()
.TheDefault.Is.ConstructedBy(CTX = GT; ctx.GetInstance&下; ConfigurationStore>());
ForRequestedType&所述; IMappingEngine方式>()TheDefaultIsConcreteType&所述;引擎(MappingEngine)>();
ForRequestedType&所述; ITypeMapFactory方式>()TheDefaultIsConcreteType&所述; TypeMapFactory>();
}
}
解决方案
我想我知道了。 。让我知道如果我错过了什么。
集装箱
.RegisterType< ConfigurationStore,ConfigurationStore>
(
新ContainerControlledLifetimeManager()
,新InjectionConstructor(typeof运算(ITypeMapFactory)
,MapperRegistry.AllMappers())
)
.RegisterType< IConfigurationProvider, ConfigurationStore>()
.RegisterType< IConfiguration,ConfigurationStore>()
.RegisterType< IMappingEngine,引擎(MappingEngine)>()
.RegisterType< ITypeMapFactory,TypeMapFactory>();
I'm not that familiar with Unity or StructureMap. How do you convert the following StructureMap registration sample into Unity registration syntax?
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>();
}
}
解决方案
I think I got it. Let me know if I missed something.
Container
.RegisterType<ConfigurationStore, ConfigurationStore>
(
new ContainerControlledLifetimeManager()
, new InjectionConstructor(typeof(ITypeMapFactory)
, MapperRegistry.AllMappers())
)
.RegisterType<IConfigurationProvider, ConfigurationStore>()
.RegisterType<IConfiguration, ConfigurationStore>()
.RegisterType<IMappingEngine, MappingEngine>()
.RegisterType<ITypeMapFactory, TypeMapFactory>();
这篇关于AutoMapper登记团结DI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!