【发布时间】:2017-03-21 02:44:03
【问题描述】:
我需要在 ASP.NET Core 1.0 Web 应用程序的 ConfigureServices 方法中设置一些依赖项(服务)。
问题是基于新的 JSON 配置,我需要设置一个服务或其他服务。
我似乎无法真正阅读应用程序生命周期的ConfigureServices 阶段的设置:
public void ConfigureServices(IServiceCollection services)
{
var section = Configuration.GetSection("MySettings"); // this does not actually hold the settings
services.Configure<MySettingsClass>(section); // this is a setup instruction, I can't actually get a MySettingsClass instance with the settings
// ...
// set up services
services.AddSingleton(typeof(ISomething), typeof(ConcreteSomething));
}
我需要真正阅读该部分并决定注册ISomething 的内容(可能与ConcreteSomething 不同)。
【问题讨论】:
-
@ademcaglin:谢谢!就是这样。我投票结束我自己的问题作为那个问题的副本:)
-
链接的答案是从配置文件中获取值,而不是从 appsettings.json 文件中获取值。
标签: configuration asp.net-core app-config startup sections