Last active
September 6, 2017 20:10
-
-
Save codehaks/61d026c46c0293435cab375290c24980 to your computer and use it in GitHub Desktop.
Simulating app.Run with app.Use in ASP.NET Core 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Extensions.DependencyInjection; | |
namespace MiddlewareDemo | |
{ | |
public class Startup | |
{ | |
public void Configure(IApplicationBuilder app) | |
{ | |
////--- Default app.Run usage ---------------------------- | |
// app.Run(async (context) => | |
// { | |
// await context.Response.WriteAsync("Hello World! 0"); | |
// }); | |
////--- Default app.Use - short-cricuit-------------------- | |
app.Use(async (context, next) => | |
{ | |
await context.Response.WriteAsync("Hello World! 1"); | |
}); | |
////--- simulating app.Run with a handler ----------------- | |
// RequestDelegate handler=async (context) => | |
// { | |
// await context.Response.WriteAsync("Hello World! 2"); | |
// }; | |
// app.Use(_ => handler); | |
////--- simulating app.Run with an anonymous function------ | |
// app.Use(_ => async (context) => | |
// { | |
// await context.Response.WriteAsync("Hello World! 3"); | |
// }); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment