What are the benefits (if any) of using AutoMapper IMappingEngine with DI

I'm relatively new to AutoMapper (but love it already) and declare my mapping profiles using Mapper.CreateMap<T,T>()through a static method called Global.asax.cs.

However, after reading more about AutoMapper, I also noticed the possibility of entering an interface IMapperEngineusing the IoC container (StructureMap in my case) and DI, which made me wonder what (if any) additional advantages to introduce me , besides those that were obtained when using Injection Dependency (bullying, inversion of control, etc.).

For example, is IMapperEngine used to upload profiles loading until they are used or I completely mark?

+4
source share
1 answer

I am relatively new to AutoMapper (but love it already) and have been declaring my mapping profiles using Mapper.Map using a static method called in Global.asax.cs.

I hope you do not. The method is Mapper.Mapused to perform actual matching between instances of an object. What you should do in Global.asax.csdefines your mappings using a static method Mapper.CreateMap.

, IMapperEngine, . hardcoding Mapper.Map, , unit test. .

. Mapper.Engine, , , IMapperEngine.Map, Mapper.Engine.Map.

+4

Source: https://habr.com/ru/post/1523338/


All Articles