[英]AutoMapper registration in Unity DI
我對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>();
}
}
我想我明白了。 如果我錯過了什么,請告訴我。
Container
.RegisterType<ConfigurationStore, ConfigurationStore>
(
new ContainerControlledLifetimeManager()
, new InjectionConstructor(typeof(ITypeMapFactory)
, MapperRegistry.AllMappers())
)
.RegisterType<IConfigurationProvider, ConfigurationStore>()
.RegisterType<IConfiguration, ConfigurationStore>()
.RegisterType<IMappingEngine, MappingEngine>()
.RegisterType<ITypeMapFactory, TypeMapFactory>();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.