當我們創建好一個新的ASP.NET Core Web應用時,系統會使用CreateDefaultBuilder方法,這個方法完成了以下操作:
- use Kestrel as the web server and configure it using the application's configuration providers
- set the ContentRootPath to the result of GetCurrentDirectory()
- load IConfiguration from 'appsettings.json' and 'appsettings.[EnvironmentName].json'
- load IConfiguration from User Secrets when EnvironmentName is 'Development' using the entry assembly,
- load IConfiguration from environment variables
- configure the ILoggerFactory to log to the console and debug output
- and enable IIS integration
如果使用了CreateDefaultBuilder的有參數版本,則還會通過命令行參數來初始化IConfiguration。
以上內容來源於官方文檔:microsoft.aspnetcore.webhost.createdefaultbuilder