using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System.Net;
namespace FastGithub.Scanner
{
///
/// github解析器
///
[Service(ServiceLifetime.Singleton, ServiceType = typeof(IGithubResolver))]
sealed class GithubResolver : IGithubResolver
{
private readonly GithubScanResults githubScanResults;
private readonly IOptionsMonitor options;
///
/// github解析器
///
///
///
public GithubResolver(
GithubScanResults githubScanResults,
IOptionsMonitor options)
{
this.githubScanResults = githubScanResults;
this.options = options;
}
///
/// 是否支持指定的域名
///
///
///
public bool IsSupported(string domain)
{
return this.options.CurrentValue.Domains.Contains(domain);
}
///
/// 解析指定的域名
///
///
///
public IPAddress? Resolve(string domain)
{
return this.IsSupported(domain) ? this.githubScanResults.FindBestAddress(domain) : default;
}
}
}