Mapper.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using Quadarax.Foundation.Core.Data.Interface.Entity;
  3. using Quadarax.Foundation.Core.Mapper;
  4. namespace Quadarax.Foundation.Core.Data.Mapper
  5. {
  6. public class Mapper<TMapper> : Loom where TMapper : class, new()
  7. {
  8. /// <summary>
  9. /// Singleton instance of this class.
  10. /// </summary>
  11. public static TMapper Instance => _instance.Value;
  12. private static readonly Lazy<TMapper> _instance = new Lazy<TMapper>(() => new TMapper());
  13. #region ------ Constructors ---------------------------------------------------------------
  14. /// <summary>
  15. /// Initializes a new instance of this class.
  16. /// </summary>
  17. public Mapper()
  18. {
  19. }
  20. /// <summary>
  21. /// Defines mappings from a DAO to DTO and vice-versa.
  22. /// </summary>
  23. /// <typeparam name="TDao"></typeparam>
  24. /// <typeparam name="TDto"></typeparam>
  25. protected void DefineBiDirection<TDao, TDto, TKey>()
  26. where TDao : class, IDao<TKey>, new()
  27. where TDto : class, IDto, new()
  28. where TKey : IEquatable<TKey>
  29. {
  30. Define<TDao, TDto>()
  31. .PublicProperties()
  32. .Compile();
  33. Define<TDto, TDao>()
  34. .PublicProperties()
  35. .Compile();
  36. }
  37. #endregion
  38. }
  39. }