IPSearcherExtensions.cs 730 B

123456789101112131415161718192021
  1. using Microsoft.Extensions.DependencyInjection;
  2. using Microsoft.Extensions.DependencyInjection.Extensions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace TEAMModelOS.SDK
  9. {
  10. public static class IPSearcherExtensions
  11. {
  12. public static IServiceCollection AddIPSearcher(this IServiceCollection services, string path, string name = "Default")
  13. {
  14. if (services == null) throw new ArgumentNullException(nameof(services));
  15. if (path == null) throw new ArgumentNullException(nameof(path));
  16. services.TryAddSingleton(new IPSearcher($"{path}/ip2region.db"));
  17. return services;
  18. }
  19. }
  20. }