Skip to content

Instantly share code, notes, and snippets.

@codehaks
Last active September 6, 2017 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codehaks/61d026c46c0293435cab375290c24980 to your computer and use it in GitHub Desktop.
Save codehaks/61d026c46c0293435cab375290c24980 to your computer and use it in GitHub Desktop.
Simulating app.Run with app.Use in ASP.NET Core 2
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