GenericLoader.cs 667 B

1234567891011121314151617181920212223242526
  1. using JLHHJSvr.Helper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace LJLib
  9. {
  10. public class GenericLoader<TKey, TValue> : ICacheLoader<TKey, TValue>
  11. where TValue : class, new()
  12. {
  13. private readonly ICacheMapping<TKey, TValue> _mapping;
  14. public GenericLoader(ICacheMapping<TKey, TValue> mapping)
  15. {
  16. _mapping = mapping ?? throw new ArgumentNullException(nameof(mapping));
  17. }
  18. public TValue Load(SqlCommand cmd, TKey id)
  19. {
  20. return _mapping.GetInstance(cmd, id);
  21. }
  22. }
  23. }