标签:pipe action name apr routes cat web iap 中间件
对于像我这样没接触过core的人,坑还是比较多的,一些基础配置和以前差别很大,这里做下记录
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// services.AddTransient<IUser, User>();
//services.AddSingleton<IUser>(new User());
services.AddSingleton<IUser, User>();
//services.AddScoped<>();//作用域注入
services.AddMemoryCache(); //MemoryCache缓存注入
}
听起来很蒙,其实就是用于处理我们程序中的各种中间件,它必须接收一个IApplicationBuilder参数,我们可以手动补充IApplicationBuilder的Use扩展方法,将中间件加到Configure中,用于满足我们的需求。
// 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();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
Program.cs这个文件包含了 ASP.NET Core 应用的 Main 方法,负责配置和启动应用程序。
core1.0和2.0的program写法是不一样的(如下),但是本质是一样的,目的都是创建一个WebHostBuilder(WEB主机构建器,自己翻译的,呵呵),然后进行构建(Build),最后运行(Run)
标签:pipe action name apr routes cat web iap 中间件
原文地址:https://www.cnblogs.com/yinchh/p/10395186.html