MapperObject.cs 679 B

1234567891011121314151617181920212223242526
  1. using AutoMapper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace MTWorkHR.Application.Mapper
  8. {
  9. public class MapperObject
  10. {
  11. private static readonly Lazy<IMapper> Lazy = new Lazy<IMapper>(() =>
  12. {
  13. var config = new MapperConfiguration(cfg =>
  14. {
  15. cfg.ShouldMapProperty = p => p.GetMethod.IsPublic || p.GetMethod.IsAssembly;
  16. cfg.AddProfile<MappingProfile>();
  17. });
  18. var mapper = config.CreateMapper();
  19. return mapper;
  20. });
  21. public static IMapper Mapper => Lazy.Value;
  22. }
  23. }