我在Startup.ConfigureServices()中有此代码,当在本地运行Windows服务时,该代码运行良好。但是当我对应用程序进行dockerize时,出现以下错误:
无法解析以下类型的“ System.Net.Http.HttpClient”服务 类型为“配置”的参数“ httpClient” ‘MyProject.WindowsService.Startup
try
{
services.AddSingleton(new HttpClient(new HttpClientHandler { })
{
DefaultRequestHeaders ={
Authorization =
new AuthenticationHeaderValue("Bearer",this.JSONWebToken.Value)
}
});
}
catch(Exception ex)
{
Console.WriteLine($"Error in Startup.ConfigureServices() {ex.Message}");
}
这是我的docker文件
FROM microsoft/aspnet:4.7.2-windowsservercore-ltsc2016
EXPOSE 32700
WORKDIR /WinService
COPY dotnet-sdk-2.2.104-win-x64.exe ./
RUN Start-Process 'dotnet-sdk-2.2.104-win-x64.exe' '/quiet' -PassThru | Wait-Process;
COPY WindowsService/bin/Release/* ./
COPY WindowsService/launcher.bat .
ENTRYPOINT ["MyProject.WindowsService.exe", "--consolemode=true"]