0
在編寫項目時,我發現Automapper可以使應用程序的映射過程變得更容易(也更容易測試)。現在我只是看Automapper的可能性。AutoMapper中的ConstructUsingServiceLocator
我在界面IMappingExpression中找到一個函數:ConstructUsingServiceLocator何時使用此方法,以及與Constructusing有什麼不同?
在此先感謝
在編寫項目時,我發現Automapper可以使應用程序的映射過程變得更容易(也更容易測試)。現在我只是看Automapper的可能性。AutoMapper中的ConstructUsingServiceLocator
我在界面IMappingExpression中找到一個函數:ConstructUsingServiceLocator何時使用此方法,以及與Constructusing有什麼不同?
在此先感謝
它是用來AutoMapper配置爲使用特定的構造函數實例化一個類。
Mapper.Initialize(cfg =>
{
// Adding "Construct" configuration
cfg.ConstructServicesUsing(t => new Dest(5));
// Telling AutoMapper to use already defined configuration to construct Dest class
cfg.CreateMap<Source, Dest>()
.ConstructUsingServiceLocator();
});
學習AutoMapper的最好方法是查看unit tests。