Last active
June 18, 2016 08:46
-
-
Save niisar/19c2715db65210f12707b8503e6d2d55 to your computer and use it in GitHub Desktop.
KatanaConsole.cs
This file contains hidden or 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.Text; | |
using System.Threading.Tasks; | |
using Owin; | |
using Microsoft.Owin.Hosting; | |
using Microsoft.Owin; | |
using System.IO; | |
namespace KatanaConsole | |
{ | |
// use an alias for the OWiN AppFunc | |
using AppFunc = Func<IDictionary<string, object>, Task>; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
WebApp.Start<Startup>("http://localhost:4321"); | |
Console.WriteLine("Server Started; Press enter to Quit"); | |
Console.ReadKey(); | |
} | |
} | |
public class Startup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
var middleware = new Func<AppFunc, AppFunc>(MyMiddleWare); | |
var otherMiddleware = new Func<AppFunc, AppFunc>(MyOtherMiddleWare); | |
app.Use(middleware); | |
app.Use(otherMiddleware); | |
} | |
public AppFunc MyMiddleWare(AppFunc next) | |
{ | |
AppFunc appFunc = async (IDictionary<string, object> environment) => | |
{ | |
// Do something with the incoming request: | |
var response = environment["owin.ResponseBody"] as Stream; | |
using (var writer = new StreamWriter(response)) | |
{ | |
await writer.WriteAsync("<h1>Hello First Middleware</h1>"); | |
} | |
// Call the next Middleware in the chain: | |
await next.Invoke(environment); | |
}; | |
return appFunc; | |
} | |
public AppFunc MyOtherMiddleWare(AppFunc next) | |
{ | |
AppFunc appFunc = async (IDictionary<string, object> environment) => | |
{ | |
// Do something with the incoming request: | |
var response = environment["owin.ResponseBody"] as Stream; | |
using (var writer = new StreamWriter(response)) | |
{ | |
await writer.WriteAsync("<h1>Hello Second Middleware</h1>"); | |
} | |
// Call the next Middleware in the chain: | |
await next.Invoke(environment); | |
}; | |
return appFunc; | |
} | |
} | |
} |
This file contains hidden or 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.Text; | |
using System.Threading.Tasks; | |
using Owin; | |
using Microsoft.Owin.Hosting; | |
using Microsoft.Owin; | |
using System.IO; | |
namespace KatanaConsole | |
{ | |
// use an alias for the OWiN AppFunc | |
using AppFunc = Func<IDictionary<string, object>, Task>; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
WebApp.Start<Startup>("http://localhost:4321"); | |
Console.WriteLine("Server Started; Press enter to Quit"); | |
Console.ReadKey(); | |
} | |
} | |
public class Startup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
var middleware = new Func<AppFunc, AppFunc>(MyMiddleWare); | |
var otherMiddleware = new Func<AppFunc, AppFunc>(MyOtherMiddleWare); | |
app.Use(middleware); | |
app.Use(otherMiddleware); | |
} | |
public AppFunc MyMiddleWare(AppFunc next) | |
{ | |
AppFunc appFunc = async (IDictionary<string, object> environment) => | |
{ | |
// Do something with the incoming request: | |
var response = environment["owin.ResponseBody"] as Stream; | |
using (var writer = new StreamWriter(response)) | |
{ | |
await writer.WriteAsync("<h1>Hello First Middleware</h1>"); | |
} | |
// Call the next Middleware in the chain: | |
// await next.Invoke(environment); | |
}; | |
return appFunc; | |
} | |
public AppFunc MyOtherMiddleWare(AppFunc next) | |
{ | |
AppFunc appFunc = async (IDictionary<string, object> environment) => | |
{ | |
// Do something with the incoming request: | |
var response = environment["owin.ResponseBody"] as Stream; | |
using (var writer = new StreamWriter(response)) | |
{ | |
await writer.WriteAsync("<h1>Hello Second Middleware</h1>"); | |
} | |
// Call the next Middleware in the chain: | |
await next.Invoke(environment); | |
}; | |
return appFunc; | |
} | |
} | |
} |
This file contains hidden or 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.Text; | |
using System.Threading.Tasks; | |
using Owin; | |
using Microsoft.Owin.Hosting; | |
using Microsoft.Owin; | |
using System.IO; | |
namespace KatanaConsole | |
{ | |
// use an alias for the OWiN AppFunc | |
using AppFunc = Func<IDictionary<string, object>, Task>; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
WebApp.Start<Startup>("http://localhost:4321"); | |
Console.WriteLine("Server Started; Press enter to Quit"); | |
Console.ReadKey(); | |
} | |
} | |
public class Startup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
var middleware = new Func<AppFunc, AppFunc>(MyMiddleWare); | |
app.Use(middleware); | |
} | |
public AppFunc MyMiddleWare(AppFunc next) | |
{ | |
AppFunc appFunc = async (IDictionary<string, object> environment) => | |
{ | |
// Do something with the incoming request: | |
var response = environment["owin.ResponseBody"] as Stream; | |
using (var writer = new StreamWriter(response)) | |
{ | |
await writer.WriteAsync("<h1>Hello First Middleware</h1>"); | |
} | |
// Call the next Middleware in the chain: | |
await next.Invoke(environment); | |
}; | |
return appFunc; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment