- 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?}");
});
}
}
推薦閱讀
- Software Defined Networking with OpenFlow
- 案例式C語言程序設計
- Hands-On Data Structures and Algorithms with JavaScript
- SQL for Data Analytics
- SSM輕量級框架應用實戰
- 嚴密系統設計:方法、趨勢與挑戰
- Java EE 8 Application Development
- 一本書講透Java線程:原理與實踐
- iPhone應用開發從入門到精通
- Mastering C++ Multithreading
- 數據結構:Python語言描述
- 例解Python:Python編程快速入門踐行指南
- Java EE 7 Development with WildFly
- 網絡綜合布線與組網實戰指南
- JBoss AS 7 Development