我正在使用 .NET Core 3.1。
在启动时,我添加以下内容:
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient<IApns, Apns>().ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler { SslProtocols = SslProtocols.Tls12 };
// How do I access memory cache (MyConfig expect it) - normally I use it injected.
var certificate = new MyConfig(...).GetCertificate
handler.ClientCertificates.Add(certificate);
return handler;
});
}
问题是MyConfig
一个期望的类IMemoryCache
:
public MyConfig(IMemoryCache cache)
{
_cache = cache;
}
证书从内存缓存中存储和加载。请问我该如何解决?