类型重命名

This commit is contained in:
老九 2021-09-08 14:28:11 +08:00
parent 0811f175c8
commit 19bd5550ad
3 changed files with 13 additions and 15 deletions

View File

@ -1,7 +1,5 @@
using FastGithub.Configuration; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
@ -13,30 +11,26 @@ namespace FastGithub.Dns
/// <summary> /// <summary>
/// dns后台服务 /// dns后台服务
/// </summary> /// </summary>
sealed class DnsOverUdpHostedService : BackgroundService sealed class DnsHostedService : BackgroundService
{ {
private readonly DnsOverUdpServer dnsOverUdpServer; private readonly DnsOverUdpServer dnsOverUdpServer;
private readonly IEnumerable<IConflictValidator> conflictValidators; private readonly IEnumerable<IConflictValidator> conflictValidators;
private readonly ILogger<DnsOverUdpHostedService> logger; private readonly ILogger<DnsHostedService> logger;
/// <summary> /// <summary>
/// dns后台服务 /// dns后台服务
/// </summary> /// </summary>
/// <param name="dnsOverUdpServer"></param> /// <param name="dnsOverUdpServer"></param>
/// <param name="conflictValidators"></param> /// <param name="conflictValidators"></param>
/// <param name="options"></param>
/// <param name="logger"></param> /// <param name="logger"></param>
public DnsOverUdpHostedService( public DnsHostedService(
DnsOverUdpServer dnsOverUdpServer, DnsOverUdpServer dnsOverUdpServer,
IEnumerable<IConflictValidator> conflictValidators, IEnumerable<IConflictValidator> conflictValidators,
IOptionsMonitor<FastGithubOptions> options, ILogger<DnsHostedService> logger)
ILogger<DnsOverUdpHostedService> logger)
{ {
this.dnsOverUdpServer = dnsOverUdpServer; this.dnsOverUdpServer = dnsOverUdpServer;
this.conflictValidators = conflictValidators; this.conflictValidators = conflictValidators;
this.logger = logger; this.logger = logger;
options.OnChange(opt => SystemDnsUtil.FlushResolverCache());
} }
/// <summary> /// <summary>
@ -54,7 +48,7 @@ namespace FastGithub.Dns
} }
catch (Exception ex) catch (Exception ex)
{ {
this.logger.LogError($"DNS服务启动失败{ex.Message}{Environment.NewLine}请配置系统或浏览器使用{nameof(FastGithub)}的DoH或向系统hosts文件添加github相关域名的ip为127.0.0.1"); this.logger.LogError($"DNS服务启动失败{ex.Message}{Environment.NewLine}请配置系统或浏览器使用{nameof(FastGithub)}的DoHhttps://127.0.0.1/dns-query或向系统hosts文件添加github相关域名的ip为127.0.0.1");
} }
foreach (var item in this.conflictValidators) foreach (var item in this.conflictValidators)

View File

@ -1,6 +1,7 @@
using DNS.Protocol; using DNS.Protocol;
using FastGithub.Configuration; using FastGithub.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System; using System;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
@ -28,10 +29,13 @@ namespace FastGithub.Dns
/// <param name="logger"></param> /// <param name="logger"></param>
public DnsOverUdpServer( public DnsOverUdpServer(
RequestResolver requestResolver, RequestResolver requestResolver,
ILogger<DnsOverUdpServer> logger) ILogger<DnsOverUdpServer> logger,
IOptionsMonitor<FastGithubOptions> options)
{ {
this.requestResolver = requestResolver; this.requestResolver = requestResolver;
this.logger = logger; this.logger = logger;
options.OnChange(opt => SystemDnsUtil.FlushResolverCache());
} }
/// <summary> /// <summary>

View File

@ -21,7 +21,7 @@ namespace FastGithub
services.TryAddSingleton<DnsOverHttpsMiddleware>(); services.TryAddSingleton<DnsOverHttpsMiddleware>();
services.AddSingleton<IConflictValidator, HostsConflictValidator>(); services.AddSingleton<IConflictValidator, HostsConflictValidator>();
services.AddSingleton<IConflictValidator, ProxyConflictValidtor>(); services.AddSingleton<IConflictValidator, ProxyConflictValidtor>();
return services.AddHostedService<DnsOverUdpHostedService>(); return services.AddHostedService<DnsHostedService>();
} }
} }
} }