Created
April 6, 2016 01:34
-
-
Save DmitryZinchenko/0123c9d11472f59c835ec5dc06aea950 to your computer and use it in GitHub Desktop.
OWIN Middleware
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.Threading.Tasks; | |
using Owin; | |
namespace Middlewares | |
{ | |
using AppFunc = Func<IDictionary<string, object>, Task>; | |
public class Startup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
var middleware = new Middleware(); | |
app.Use(middleware, 10, "auth"); | |
} | |
} | |
internal class Middleware | |
{ | |
private AppFunc _next; | |
private int _number; | |
private string _name; | |
public void Initialize(AppFunc next, int number, string name) | |
{ | |
_next = next; | |
_number = number; | |
_name = name; | |
} | |
public async Task Invoke(IDictionary<string, object> env) | |
{ | |
Console.WriteLine("before. number: {0}, name: {1}", _number, _name); | |
await _next.Invoke(env); | |
Console.WriteLine("after. number: {0}, name: {1}", _number, _name); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment