- Hands-On Full:Stack Web Development with ASP.NET Core
- Tamir Dresher Amir Zuker Shay Friedman
- 170字
- 2021-06-10 19:37:23
Changing the Startup class name
The name of the Startup class is a convention of ASP.NET Core applications. It is recommended to leave it as it is to make the code clearer for colleagues. However, there are a few situations where you are required to use a different name for the Startup class—for example, when Startup is already a class in your application but is responsible for an entirely different task than initializing ASP.NET Core.
On such occasions, open the Program class file, located in the root folder under Program.cs, and locate the CreateWebHostBuilder method. It should look similar to the following:
public static IWebHostBuilder CreateWebHostBuiler(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
In order to point ASP.NET Core to a different class name, for example, to CustomStartup, change the UseStartup<Startup>() line to UseStartup<CustomStartup>:
public static IWebHostBuilder CreateWebHostBuiler(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
If you're using different Startup classes for each environment, changing the name will affect the suffix. For example, instead of StartupDevelopment, ASP.NET Core will look for a CustomStartupDevelopment class.
推薦閱讀
- 6G潛在關鍵技術(下冊)
- 解析QUIC/HTTP3:未來互聯網的基石
- 從區塊鏈到Web3:構建未來互聯網生態
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- 信息通信網絡建設安全管理概要2
- 物聯網時代
- SSL VPN : Understanding, evaluating and planning secure, web/based remote access
- Mastering JavaFX 10
- Learning Swift(Second Edition)
- Working with Legacy Systems
- 4G小基站系統原理、組網及應用
- AWS Lambda Quick Start Guide
- 商業的本質和互聯網
- 5G智慧交通
- Architecting Data:Intensive Applications