我设法在控制台应用程序中配置
UserSecret
,我基本上用App
替换Program
,但似乎以下(简化的)代码似乎不适用于WPF应用程序。
public static IHostBuilder AddServices(this IHostBuilder host)
{
host.ConfigureServices((context, services) =>
{
var builder = new ConfigurationBuilder()
.AddUserSecrets<App>() // I don't know if it is 'App' to use as the generic.
.Build();
var config = builder.GetSection(nameof(UserSecretModel));
services.Configure<UserSecretModel>(config);
});
return host;
}
有人可以分享他的见解吗?
我相信我对
GetSection()
感到困惑,我最终删除了它,一切似乎都工作正常。
public static IHostBuilder AddServices(this IHostBuilder host)
{
host.ConfigureServices((context, services) =>
{
var configuration = new ConfigurationBuilder()
.AddUserSecrets<App>
.Build();
services.Configure<UserSecretModel>(configuration);
});
return host;
}