我需要在ASP.NET Core 1.0 Web應用程序的ConfigureServices
方法中設置一些依賴關係(服務)。實際上在ASP.NET Core的ConfigureServices階段閱讀AppSettings
問題是,基於新的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
)。
見http://stackoverflow.com/q/40397648/5426333 –
@ademcaglin:謝謝!就是這樣。我投了贊成關閉自己的問題:) –
鏈接的答案是從配置文件中獲取值,而不是appsettings.json文件。 – im1dermike