我正在為 .NET 6 制作一個 C# 類別庫,它為 Web 配置和 HTTP 進行了一系列設定。在IServiceCollection我試圖呼叫Configure需要一個部分的方法,如下所示:
IServiceCollection services = ...
IConfigurationSection section = ...
services.Configure<MySettings>(section);
如果我在 Web 專案中做到這一點,效果會很好。在類別庫專案中,IConfigurationSection不存在采用 an 的擴展方法。
在 web 專案中,這似乎來自 Microsoft.Extensions.DependencyInjection,但它必須在其他地方。對于庫專案,我包含了以下 NuGet 包。
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.13" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.15.0" />
</ItemGroup>
uj5u.com熱心網友回復:
您缺少Microsoft.Extensions.Options.ConfigurationExtensions包。
另請注意,OptionsConfigurationServiceCollectionExtensions.Configure多載接受IConfiguration介面,它是IConfigurationSection.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/404838.html
標籤:
上一篇:更改DotNet6入站請求超時
