- Modern Web Development with ASP.NET Core 3
- Ricardo Peres
- 212字
- 2021-06-18 18:35:56
Changes from version 2.x
The big change from version 2.0 was that, as of 2.1, the configuration is done by convention—that is, the process of adding appsettings.json JSON files (generic and optional per environment) and all that is hidden from the users.
This is defined in the WebHost.CreateDefaultBuilder method. You can, however, still build your own ConfigurationBuilder and add whatever you like to it. To do this, you call the ConfigureAppConfiguration method, as described in Chapter 1, Getting Started with ASP.NET Core, and illustrated in the following code block:
Host .CreateDefaultBuilder(args) .ConfigureAppConfiguration(builder => {
var jsonSource = new JsonConfigurationSource { Path =
"appsettings.json" }; builder.Add(jsonSource);
})
.ConfigureWebHostDefaults(builder =>
{
builder.UseStartup<Startup>();
});
Or, if you just want to add a single entry to the configuration that is built by default (or, to the one you're modifying), you call the UseSettings extension method, as follows:
Host .CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(builder =>
{
builder.UseSetting("key", "value");
builder.UseStartup<Startup>();
});
So, when the Startup class is instantiated, it will get passed an IConfiguration object that is built from the code that you put in here.
After seeing how the application configuration is done, let's see how we can do the same for the host.
- Android項目開發入門教程
- Learning Docker
- 深入淺出Java虛擬機:JVM原理與實戰
- Learning Flask Framework
- Flash CS6中文版應用教程(第三版)
- JavaScript by Example
- 數據結構案例教程(C/C++版)
- 用戶體驗可視化指南
- OpenResty完全開發指南:構建百萬級別并發的Web應用
- 深度實踐KVM:核心技術、管理運維、性能優化與項目實施
- Visual Basic語言程序設計上機指導與練習(第3版)
- C#程序開發參考手冊
- Web程序設計與架構
- 瘋狂Ajax講義(第3版)
- Android Application Programming with OpenCV 3