IPSearcherExtensions.cs 768 B

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