Updated the samples project for net45 to use owin.

This commit is contained in:
David Fowler 2014-01-25 16:04:50 -08:00
parent 1d27b4e2e4
commit 2bd1aab88d
5 changed files with 209 additions and 4 deletions

View File

@ -35,6 +35,7 @@
<ItemGroup>
<Compile Include="Home2Controller.cs" />
<Compile Include="HomeController.cs" />
<Compile Include="OwinHttpContext.cs" />
<Compile Include="Startup.cs" />
<Compile Include="ViewMetadata.cs" />
<Compile Include="Models\Class1.cs" />
@ -51,6 +52,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140125104446\lib\k10\Microsoft.AspNet.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.DependencyInjection, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.DependencyInjection.0.1-alpha-t140125113429\lib\k10\Microsoft.AspNet.DependencyInjection.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNet.Mvc\Microsoft.AspNet.Mvc.k10.csproj">

View File

@ -38,6 +38,18 @@
<Reference Include="System.Core"/>
<Reference Include="Microsoft.CSharp"/>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.Owin.2.1.0\lib\net45\Microsoft.Owin.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Diagnostics, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.Owin.Diagnostics.2.1.0\lib\net40\Microsoft.Owin.Diagnostics.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.FileSystems, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.FileSystems.0.1-alpha-t140125101521\lib\net45\Microsoft.AspNet.FileSystems.dll</HintPath>
@ -46,10 +58,15 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140125104446\lib\net45\Microsoft.AspNet.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.DependencyInjection, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.DependencyInjection.0.1-alpha-t140125113429\lib\net45\Microsoft.AspNet.DependencyInjection.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Home2Controller.cs" />
<Compile Include="HomeController.cs" />
<Compile Include="OwinHttpContext.cs" />
<Compile Include="Startup.cs" />
<Compile Include="ViewMetadata.cs" />
<Compile Include="Models\Class1.cs" />

View File

@ -0,0 +1,177 @@
#if NET45
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNet.Abstractions;
using Microsoft.Owin;
namespace MvcSample
{
public class OwinHttpContext : HttpContext
{
private readonly IOwinContext _context;
private readonly HttpRequest _request;
private readonly HttpResponse _response;
public OwinHttpContext(IOwinContext context)
{
_context = context;
_request = new OwinHttpRequest(this, context.Request);
_response = new OwinHttpResponse(this, context.Response);
}
public override void Dispose()
{
}
public override object GetInterface(Type type)
{
return null;
}
public override HttpRequest Request
{
get { return _request; }
}
public override HttpResponse Response
{
get { return _response; }
}
public override void SetInterface(Type type, object instance)
{
}
private class OwinHttpRequest : HttpRequest
{
private HttpContext _context;
private IOwinRequest _request;
public OwinHttpRequest(HttpContext context, IOwinRequest request)
{
_context = context;
_request = request;
}
public override Stream Body
{
get
{
return _request.Body;
}
set
{
_request.Body = value;
}
}
public override HttpContext HttpContext
{
get { return _context; }
}
public override Microsoft.AspNet.Abstractions.PathString Path
{
get
{
return new Microsoft.AspNet.Abstractions.PathString(_request.Path.Value);
}
set
{
_request.Path = new Microsoft.Owin.PathString(value.Value);
}
}
public override Microsoft.AspNet.Abstractions.PathString PathBase
{
get
{
return new Microsoft.AspNet.Abstractions.PathString(_request.PathBase.Value);
}
set
{
_request.PathBase = new Microsoft.Owin.PathString(value.Value);
}
}
public override Microsoft.AspNet.Abstractions.QueryString QueryString
{
get
{
return new Microsoft.AspNet.Abstractions.QueryString(_request.QueryString.Value);
}
set
{
_request.QueryString = new Microsoft.Owin.QueryString(value.Value);
}
}
public override Uri Uri
{
get { return _request.Uri; }
}
}
private class OwinHttpResponse : HttpResponse
{
private readonly HttpContext _context;
private readonly IOwinResponse _response;
public OwinHttpResponse(HttpContext context, IOwinResponse response)
{
_context = context;
_response = response;
}
public override Stream Body
{
get
{
return _response.Body;
}
set
{
_response.Body = value;
}
}
public override string ContentType
{
get
{
return _response.ContentType;
}
set
{
_response.ContentType = value;
}
}
public override HttpContext HttpContext
{
get { return _context; }
}
public override int StatusCode
{
get
{
return _response.StatusCode;
}
set
{
_response.StatusCode = value;
}
}
public override Task WriteAsync(string data)
{
return _response.WriteAsync(data);
}
}
}
}
#endif

View File

@ -1,4 +1,4 @@
#if OWIN
#if NET45
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
@ -32,10 +32,12 @@ namespace MvcSample
app.Run(async context =>
{
// Pretending to be routing
var routeData = new FakeRouteData(context);
var httpContext = new OwinHttpContext(context);
await handler.ExecuteAsync(context, routeData);
// Pretending to be routing
var routeData = new FakeRouteData(httpContext);
await handler.ExecuteAsync(httpContext, routeData);
});
}
}

View File

@ -1,8 +1,12 @@
{
"version" : "0.1-alpha-*",
"dependencies": {
"Owin": "1.0",
"Microsoft.Owin": "2.1.0",
"Microsoft.Owin.Diagnostics": "2.1.0",
"Microsoft.AspNet.FileSystems": "0.1-alpha-*",
"Microsoft.AspNet.Abstractions": "0.1-alpha-*",
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
"Microsoft.AspNet.Mvc" : "",
"Microsoft.AspNet.Mvc.Razor" : ""
},