- C# and .NET Core Test Driven Development
- Ayobami Adewole
- 201字
- 2021-06-25 22:00:34
Startup.cs
The Startup class is needed by ASP.NET Core applications to manage the application's request pipeline, configure services, and for dependency injection.
Different Startup classes can be created for different environments; for example, you can create two Startup classes in your application, one for the development environment and the other for production. You can also specify that a Startup class be used for all environments.
The Startup class has two methods—Configure(), which is compulsory and is used to determine how the application should respond to HTTP requests, and ConfigureServices(), which is optional and is used to configure services before the Configure method is called. Both methods are called when the application starts:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
推薦閱讀
- C語(yǔ)言程序設(shè)計(jì)基礎(chǔ)與實(shí)驗(yàn)指導(dǎo)
- Network Automation Cookbook
- Learning SAP Analytics Cloud
- Windows Forensics Cookbook
- PLC編程與調(diào)試技術(shù)(松下系列)
- Nginx Lua開(kāi)發(fā)實(shí)戰(zhàn)
- SQL基礎(chǔ)教程(第2版)
- AIRIOT物聯(lián)網(wǎng)平臺(tái)開(kāi)發(fā)框架應(yīng)用與實(shí)戰(zhàn)
- Python程序設(shè)計(jì)與算法基礎(chǔ)教程(第2版)(微課版)
- Java并發(fā)編程之美
- Java Web開(kāi)發(fā)實(shí)例大全(基礎(chǔ)卷) (軟件工程師開(kāi)發(fā)大系)
- Android系統(tǒng)下Java編程詳解
- Unity 2017 Game AI Programming(Third Edition)
- 高效使用Greenplum:入門(mén)、進(jìn)階與數(shù)據(jù)中臺(tái)
- Python 3快速入門(mén)與實(shí)戰(zhàn)