Created
May 25, 2014 00:34
-
-
Save davidfowl/8ea8be87fd5e1090f345 to your computer and use it in GitHub Desktop.
Nowin on ASP.NET vNext
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.Net; | |
using System.Threading.Tasks; | |
using Microsoft.AspNet.Builder; | |
using Microsoft.AspNet.Hosting.Server; | |
using Microsoft.AspNet.Owin; | |
using Microsoft.Framework.ConfigurationModel; | |
namespace Nowin.vNext | |
{ | |
// dependencies | |
// "Nowin": "0.11.0", | |
// "Microsoft.AspNet.Hosting": "0.1-alpha-*", | |
// "Microsoft.AspNet.Owin": "0.1-alpha-*" | |
public class NowinServerFactory : IServerFactory | |
{ | |
private Func<object, Task> _callback; | |
private Task HandleRequest(IDictionary<string, object> env) | |
{ | |
return _callback(new OwinFeatureCollection(env)); | |
} | |
public IServerInformation Initialize(IConfiguration configuration) | |
{ | |
// TODO: Parse config | |
var builder = ServerBuilder.New() | |
.SetAddress(IPAddress.Any) | |
.SetPort(8080) | |
.SetOwinApp(HandleRequest); | |
return new NowinServerInformation(builder); | |
} | |
public IDisposable Start(IServerInformation serverInformation, Func<object, Task> application) | |
{ | |
var information = (NowinServerInformation)serverInformation; | |
_callback = application; | |
INowinServer server = information.Builder.Build(); | |
server.Start(); | |
return server; | |
} | |
private class NowinServerInformation : IServerInformation | |
{ | |
public NowinServerInformation(ServerBuilder builder) | |
{ | |
Builder = builder; | |
} | |
public ServerBuilder Builder { get; private set; } | |
public string Name | |
{ | |
get | |
{ | |
return "Nowin"; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment