我对ASP .NET vNext有一个麻烦的问题; 更具体地说,MVC.
这是我的Startup.cs文件的简化版本:
public void ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container.
services.AddMvc();
services.AddScoped<Foo>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
{
app.Use(async (context, next) =>
{
await context.RequestServices.GetService<Foo>().Initialize(context);
await next();
});
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
// Time to save the cookie.
app.Use((context, next) =>
{
context.RequestServices.GetService<Foo>().SaveCookie();
return next();
}); …Run Code Online (Sandbox Code Playgroud) asp.net-core ×1