- 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?}");
});
}
}
推薦閱讀
- Node.js+Webpack開發實戰
- Python概率統計
- HTML5移動Web開發技術
- LabVIEW2018中文版 虛擬儀器程序設計自學手冊
- Python從菜鳥到高手(第2版)
- 高級C/C++編譯技術(典藏版)
- HTML5 and CSS3 Transition,Transformation,and Animation
- C語言程序設計同步訓練與上機指導(第三版)
- Mastering Linux Network Administration
- 單片機C語言程序設計實訓100例
- 西門子S7-200 SMART PLC編程從入門到實踐
- Swift語言實戰晉級
- Java并發編程:核心方法與框架
- HTML5移動前端開發基礎與實戰(微課版)
- 寫給青少年的人工智能(Python版·微課視頻版)