Updated the sample to use the owin http abstractions glue.

This commit is contained in:
David Fowler 2014-01-25 16:44:35 -08:00
parent 2bd1aab88d
commit 328d43a638
11 changed files with 36 additions and 212 deletions

View File

@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\K</OutputPath>
<DefineConstants>DEBUG;TRACE;K10</DefineConstants>
<DefineConstants>DEBUG;TRACE;K10;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -28,14 +28,13 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\K</OutputPath>
<DefineConstants>TRACE;K10</DefineConstants>
<DefineConstants>TRACE;K10;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<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" />
@ -46,11 +45,11 @@
<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\k10\Microsoft.AspNet.FileSystems.dll</HintPath>
<HintPath>..\..\packages\Microsoft.AspNet.FileSystems.0.1-alpha-t140125113323\lib\k10\Microsoft.AspNet.FileSystems.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Abstractions, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140125104446\lib\k10\Microsoft.AspNet.Abstractions.dll</HintPath>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140126002929\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>

View File

@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\net45</OutputPath>
<DefineConstants>DEBUG;TRACE;NET45</DefineConstants>
<DefineConstants>DEBUG;TRACE;NET45;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -28,7 +28,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\net45</OutputPath>
<DefineConstants>TRACE;NET45</DefineConstants>
<DefineConstants>TRACE;NET45;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -52,11 +52,15 @@
</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>
<HintPath>..\..\packages\Microsoft.AspNet.FileSystems.0.1-alpha-t140125113323\lib\net45\Microsoft.AspNet.FileSystems.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Abstractions, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140125104446\lib\net45\Microsoft.AspNet.Abstractions.dll</HintPath>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140126002929\lib\net45\Microsoft.AspNet.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Abstractions.Owin, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.Owin.0.1-alpha-t140126002929\lib\net45\Microsoft.AspNet.Abstractions.Owin.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.DependencyInjection, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
@ -66,7 +70,6 @@
<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

@ -1,177 +0,0 @@
#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

@ -30,14 +30,12 @@ namespace MvcSample
var handler = new MvcHandler(serviceProvider);
app.Run(async context =>
app.RunHttpContext(async context =>
{
var httpContext = new OwinHttpContext(context);
// Pretending to be routing
var routeData = new FakeRouteData(httpContext);
var routeData = new FakeRouteData(context);
await handler.ExecuteAsync(httpContext, routeData);
await handler.ExecuteAsync(context, routeData);
});
}
}

View File

@ -6,6 +6,7 @@
"Microsoft.Owin.Diagnostics": "2.1.0",
"Microsoft.AspNet.FileSystems": "0.1-alpha-*",
"Microsoft.AspNet.Abstractions": "0.1-alpha-*",
"Microsoft.AspNet.Abstractions.Owin": "0.1-alpha-*",
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
"Microsoft.AspNet.Mvc" : "",
"Microsoft.AspNet.Mvc.Razor" : ""

View File

@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\K</OutputPath>
<DefineConstants>DEBUG;TRACE;K10</DefineConstants>
<DefineConstants>DEBUG;TRACE;K10;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -28,7 +28,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\K</OutputPath>
<DefineConstants>TRACE;K10</DefineConstants>
<DefineConstants>TRACE;K10;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -49,7 +49,7 @@
<Reference Include="Microsoft.AspNet.Abstractions, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140125104446\lib\k10\Microsoft.AspNet.Abstractions.dll</HintPath>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140126002929\lib\k10\Microsoft.AspNet.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>

View File

@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\net45</OutputPath>
<DefineConstants>DEBUG;TRACE;NET45</DefineConstants>
<DefineConstants>DEBUG;TRACE;NET45;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -28,7 +28,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\net45</OutputPath>
<DefineConstants>TRACE;NET45</DefineConstants>
<DefineConstants>TRACE;NET45;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -40,7 +40,7 @@
<Reference Include="Microsoft.AspNet.Abstractions, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140125104446\lib\net45\Microsoft.AspNet.Abstractions.dll</HintPath>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140126002929\lib\net45\Microsoft.AspNet.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>

View File

@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\K</OutputPath>
<DefineConstants>DEBUG;TRACE;K10</DefineConstants>
<DefineConstants>DEBUG;TRACE;K10;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -28,7 +28,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\K</OutputPath>
<DefineConstants>TRACE;K10</DefineConstants>
<DefineConstants>TRACE;K10;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -60,11 +60,11 @@
<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\k10\Microsoft.AspNet.FileSystems.dll</HintPath>
<HintPath>..\..\packages\Microsoft.AspNet.FileSystems.0.1-alpha-t140125113323\lib\k10\Microsoft.AspNet.FileSystems.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Abstractions, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140125104446\lib\k10\Microsoft.AspNet.Abstractions.dll</HintPath>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140126002929\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>

View File

@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\net45</OutputPath>
<DefineConstants>DEBUG;TRACE;NET45</DefineConstants>
<DefineConstants>DEBUG;TRACE;NET45;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -28,7 +28,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\net45</OutputPath>
<DefineConstants>TRACE;NET45</DefineConstants>
<DefineConstants>TRACE;NET45;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -40,11 +40,11 @@
<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>
<HintPath>..\..\packages\Microsoft.AspNet.FileSystems.0.1-alpha-t140125113323\lib\net45\Microsoft.AspNet.FileSystems.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Abstractions, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140125104446\lib\net45\Microsoft.AspNet.Abstractions.dll</HintPath>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140126002929\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>

View File

@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\K</OutputPath>
<DefineConstants>DEBUG;TRACE;K10</DefineConstants>
<DefineConstants>DEBUG;TRACE;K10;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -28,7 +28,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\K</OutputPath>
<DefineConstants>TRACE;K10</DefineConstants>
<DefineConstants>TRACE;K10;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -80,7 +80,7 @@
</Reference>
<Reference Include="Microsoft.AspNet.Abstractions, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140125104446\lib\k10\Microsoft.AspNet.Abstractions.dll</HintPath>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140126002929\lib\k10\Microsoft.AspNet.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>

View File

@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\net45</OutputPath>
<DefineConstants>DEBUG;TRACE;NET45</DefineConstants>
<DefineConstants>DEBUG;TRACE;NET45;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -28,7 +28,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\net45</OutputPath>
<DefineConstants>TRACE;NET45</DefineConstants>
<DefineConstants>TRACE;NET45;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -48,7 +48,7 @@
</Reference>
<Reference Include="Microsoft.AspNet.Abstractions, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140125104446\lib\net45\Microsoft.AspNet.Abstractions.dll</HintPath>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140126002929\lib\net45\Microsoft.AspNet.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>