2
0

ServiceCollectionExtensions.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using FastGithub.PacketIntercept;
  2. using FastGithub.PacketIntercept.Dns;
  3. using FastGithub.PacketIntercept.Tcp;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Microsoft.Extensions.DependencyInjection.Extensions;
  6. using System.Runtime.Versioning;
  7. namespace FastGithub
  8. {
  9. /// <summary>
  10. /// 服务注册扩展
  11. /// </summary>
  12. public static class ServiceCollectionExtensions
  13. {
  14. /// <summary>
  15. /// 注册数据包拦截器
  16. /// </summary>
  17. /// <param name="services"></param>
  18. /// <returns></returns>
  19. [SupportedOSPlatform("windows")]
  20. public static IServiceCollection AddPacketIntercept(this IServiceCollection services)
  21. {
  22. services.AddSingleton<IDnsConflictSolver, HostsConflictSolver>();
  23. services.AddSingleton<IDnsConflictSolver, ProxyConflictSolver>();
  24. services.TryAddSingleton<IDnsInterceptor, DnsInterceptor>();
  25. services.AddHostedService<DnsInterceptHostedService>();
  26. services.AddSingleton<ITcpInterceptor, SshInterceptor>();
  27. services.AddSingleton<ITcpInterceptor, HttpInterceptor>();
  28. services.AddSingleton<ITcpInterceptor, HttpsInterceptor>();
  29. services.AddHostedService<TcpInterceptHostedService>();
  30. return services;
  31. }
  32. }
  33. }