- 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?}");
});
}
}
推薦閱讀
- Mastering Concurrency Programming with Java 8
- Learning Python Web Penetration Testing
- ASP.NET Web API:Build RESTful web applications and services on the .NET framework
- Visual FoxPro程序設計教程(第3版)
- Java EE框架整合開發入門到實戰:Spring+Spring MVC+MyBatis(微課版)
- Machine Learning with R Cookbook(Second Edition)
- Functional Programming in JavaScript
- Scratch 3游戲與人工智能編程完全自學教程
- 3D少兒游戲編程(原書第2版)
- 移動界面(Web/App)Photoshop UI設計十全大補
- Instant Ext.NET Application Development
- Essential C++(中文版)
- Python+Office:輕松實現Python辦公自動化
- 基于GPU加速的計算機視覺編程:使用OpenCV和CUDA實時處理復雜圖像數據
- Kotlin語言實例精解