- 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?}");
});
}
}
推薦閱讀
- Learning Scala Programming
- Mastering Zabbix(Second Edition)
- Linux C/C++服務器開發實踐
- 我的第一本算法書
- PHP+MySQL+Dreamweaver動態網站開發實例教程
- Python機器學習經典實例
- INSTANT Passbook App Development for iOS How-to
- Java:High-Performance Apps with Java 9
- AppInventor實踐教程:Android智能應用開發前傳
- Extreme C
- 并行編程方法與優化實踐
- Java程序設計實用教程(第2版)
- 計算機組裝與維護(第二版)
- Three.js權威指南:在網頁上創建3D圖形和動畫的方法與實踐(原書第4版)
- 少兒編程輕松學(全2冊)