Hak*_*tık 12 .net c# migration .net-5 .net-core-3.1
我有.netcore 3.1应用程序,我想将其更新为.net 5.0
我有以下代码
public static IAppSettings ConfigureAppSettings(this IServiceCollection services, IConfiguration configuration)
{
void ConfigureSection<Interface, Implementation>(string sectionName)
where Implementation : Interface, new() where Interface : class
{
Implementation configSection = new Implementation();
configuration.GetSection(sectionName).Bind(configSection);
services.AddSingleton<Interface>(configSection);
}
}
Run Code Online (Sandbox Code Playgroud)
它以前工作过,但更新到 .net5 后,我开始看到这个编译时错误
CS1061“IConfigurationSection”不包含“绑定”的定义,并且找不到接受“IConfigurationSection”类型的第一个参数的可访问扩展方法“绑定”(您是否缺少 using 指令或程序集引用?)
我的问题:该Bind方法的替代方法是什么?
Hak*_*tık 32
我安装了这个Microsoft.Extensions.Configuration.Binder包,问题解决了。
奇怪的是,当我使用时,我.net-core3.1不需要安装它,Nuget但更新后.net5我需要单独安装这个包。
| 归档时间: |
|
| 查看次数: |
3871 次 |
| 最近记录: |