C# 在AutoMapper中使用ServiceLocator构造
我在AutoMapper中找到了一个方法:C# 在AutoMapper中使用ServiceLocator构造,c#,automapper,C#,Automapper,我在AutoMapper中找到了一个方法:IMappingExpression.constructionUsingServiceLocator() 我应该在什么时候使用此方法,以及它与使用构造函数的之间的区别是什么?它用于配置AutoMapper以使用特定构造函数实例化类 Mapper.Initialize(cfg => { // Adding "Construct" configuration cfg.ConstructServicesUsing
IMappingExpression.constructionUsingServiceLocator()
我应该在什么时候使用此方法,以及它与使用
构造函数的之间的区别是什么?它用于配置AutoMapper以使用特定构造函数实例化类
Mapper.Initialize(cfg =>
{
// Adding "Construct" configuration
cfg.ConstructServicesUsing(t => new Dest(5));
// Tell AutoMapper to use already defined configuration to construct Dest class
cfg.CreateMap<Source, Dest>()
.ConstructUsingServiceLocator();
});
Mapper.Initialize(cfg=>
{
//添加“构造”配置
cfg.ConstructServicesUsing(t=>newdest(5));
//告诉AutoMapper使用已定义的配置来构造Dest类
cfg.CreateMap()
.ConstructionUsingServiceLocator();
});
学习AutoMapper的最佳方法是查看。它用于配置AutoMapper以使用特定构造函数实例化类
Mapper.Initialize(cfg =>
{
// Adding "Construct" configuration
cfg.ConstructServicesUsing(t => new Dest(5));
// Tell AutoMapper to use already defined configuration to construct Dest class
cfg.CreateMap<Source, Dest>()
.ConstructUsingServiceLocator();
});
Mapper.Initialize(cfg=>
{
//添加“构造”配置
cfg.ConstructServicesUsing(t=>newdest(5));
//告诉AutoMapper使用已定义的配置来构造Dest类
cfg.CreateMap()
.ConstructionUsingServiceLocator();
});
学习AutoMapper的最好方法是深入研究