IP2RegionExtensions.cs 781 B

1234567891011121314151617181920212223
  1. using IP2Region;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Microsoft.Extensions.DependencyInjection.Extensions;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using TEAMModelOS.SDK.DI;
  10. namespace TEAMModelOS.SDK
  11. {
  12. public static class IP2RegionExtensions
  13. {
  14. public static IServiceCollection AddIP2Region(this IServiceCollection services, string configPath)
  15. {
  16. if (services == null) throw new ArgumentNullException(nameof(services));
  17. if (configPath == null) throw new ArgumentNullException(nameof(configPath));
  18. services.TryAddSingleton(new IP2RegionFileSearcher($"{configPath}/ip2region.db"));
  19. return services;
  20. }
  21. }
  22. }