官术网_书友最值得收藏!

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.
主站蜘蛛池模板: 泰来县| 合阳县| 明光市| 那坡县| 禹城市| 五台县| 五家渠市| 周口市| 东港市| 台中县| 虞城县| 正镶白旗| 曲松县| 密山市| 丹江口市| 民乐县| 黎城县| 托克托县| 从化市| 华坪县| 龙江县| 宁安市| 灵川县| 独山县| 张家界市| 临夏县| 武山县| 多伦县| 汾阳市| 法库县| 鄱阳县| 沈丘县| 麻栗坡县| 昌平区| 鞍山市| 灵石县| 夏河县| 双流县| 岳阳县| 乐平市| 汶上县|