Skip to content
This repository was archived by the owner on Mar 20, 2019. It is now read-only.

Commit 9fac617

Browse files
committed
Moves all MVC dependencies from core assemblies to a separate assembly.
I still need to add DNOA.Mvc to some build and package authoring.
1 parent dab0ace commit 9fac617

15 files changed

Lines changed: 251 additions & 74 deletions

File tree

nuget/DotNetOpenAuth.Mvc.nuspec

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>DotNetOpenAuth.Mvc</id>
5+
<version>$version$</version>
6+
<title>DotNetOpenAuth MVC extensions</title>
7+
<authors>Andrew Arnott</authors>
8+
<owners>Outercurve Foundation</owners>
9+
<projectUrl>http://www.dotnetopenauth.net/</projectUrl>
10+
<iconUrl>https://github.com/AArnott/dotnetopenid/raw/v3.4/doc/logo/dnoa-logo_32x32.png</iconUrl>
11+
<licenseUrl>http://www.opensource.org/licenses/ms-pl.html</licenseUrl>
12+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
13+
<summary>Provides the HttpResponseMessage.AsActionResult() extension method.</summary>
14+
<dependencies>
15+
<dependency id="DotNetOpenAuth.Core" version="[$version$]" />
16+
<dependency id="Microsoft.AspNet.Mvc" version="[5.0.0,6.0)" />
17+
<dependency id="Microsoft.AspNet.Razor" version="[3.0.0,4.0)" />
18+
<dependency id="Microsoft.AspNet.WebPages" version="[3.0.0,4.0)" />
19+
<dependency id="Microsoft.Bcl" version="[1.1.3,2.0)" />
20+
<dependency id="Microsoft.Bcl.Build" version="[1.0.10,2.0)" />
21+
<dependency id="Microsoft.Net.Http" version="[2.2.15,3.0)" />
22+
<dependency id="Microsoft.Web.Infrastructure" version="[1.0.0.0,2.0)" />
23+
<dependency id="Validation" version="[2.0.2.13022,3.0)" />
24+
</dependencies>
25+
</metadata>
26+
<files>
27+
<file src="$OutputPath45$$signedSubPath$$identity$.dll" target="lib\net45-full\" />
28+
<file src="$OutputPath45$$identity$.pdb" target="lib\net45-full\" />
29+
<file src="$OutputPath45$$identity$.xml" target="lib\net45-full\" />
30+
31+
<file src="..\src\$Identity$\**\*.cs" target="src" exclude="..\src\$Identity$\obj\**" />
32+
<file src="$GeneratedAssemblyInfoSourceFile$" target="src" />
33+
</files>
34+
</package>

samples/OAuth2ProtectedWebApi/OAuth2ProtectedWebApi.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@
279279
<Project>{60426312-6ae5-4835-8667-37edea670222}</Project>
280280
<Name>DotNetOpenAuth.Core</Name>
281281
</ProjectReference>
282+
<ProjectReference Include="..\..\src\DotNetOpenAuth.Mvc\DotNetOpenAuth.Mvc.csproj">
283+
<Project>{9d308ef2-2712-4f83-a14c-18bf08d45526}</Project>
284+
<Name>DotNetOpenAuth.Mvc</Name>
285+
</ProjectReference>
282286
<ProjectReference Include="..\..\src\DotNetOpenAuth.OAuth2.AuthorizationServer\DotNetOpenAuth.OAuth2.AuthorizationServer.csproj">
283287
<Project>{99bb7543-ea16-43ee-a7bc-d7a25a3b22f6}</Project>
284288
<Name>DotNetOpenAuth.OAuth2.AuthorizationServer</Name>

samples/OAuthAuthorizationServer/OAuthAuthorizationServer.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@
198198
<Project>{60426312-6AE5-4835-8667-37EDEA670222}</Project>
199199
<Name>DotNetOpenAuth.Core</Name>
200200
</ProjectReference>
201+
<ProjectReference Include="..\..\src\DotNetOpenAuth.Mvc\DotNetOpenAuth.Mvc.csproj">
202+
<Project>{9d308ef2-2712-4f83-a14c-18bf08d45526}</Project>
203+
<Name>DotNetOpenAuth.Mvc</Name>
204+
</ProjectReference>
201205
<ProjectReference Include="..\..\src\DotNetOpenAuth.OAuth2.AuthorizationServer\DotNetOpenAuth.OAuth2.AuthorizationServer.csproj">
202206
<Project>{99BB7543-EA16-43EE-A7BC-D7A25A3B22F6}</Project>
203207
<Name>DotNetOpenAuth.OAuth2.AuthorizationServer</Name>

samples/OpenIdProviderMvc/OpenIdProviderMvc.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@
167167
<Project>{60426312-6AE5-4835-8667-37EDEA670222}</Project>
168168
<Name>DotNetOpenAuth.Core</Name>
169169
</ProjectReference>
170+
<ProjectReference Include="..\..\src\DotNetOpenAuth.Mvc\DotNetOpenAuth.Mvc.csproj">
171+
<Project>{9d308ef2-2712-4f83-a14c-18bf08d45526}</Project>
172+
<Name>DotNetOpenAuth.Mvc</Name>
173+
</ProjectReference>
170174
<ProjectReference Include="..\..\src\DotNetOpenAuth.OpenId.Provider.UI\DotNetOpenAuth.OpenId.Provider.UI.csproj">
171175
<Project>{9D0F8866-2131-4C2A-BC0E-16FEA5B50828}</Project>
172176
<Name>DotNetOpenAuth.OpenId.Provider.UI</Name>

samples/OpenIdRelyingPartyMvc/OpenIdRelyingPartyMvc.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@
184184
<Project>{60426312-6AE5-4835-8667-37EDEA670222}</Project>
185185
<Name>DotNetOpenAuth.Core</Name>
186186
</ProjectReference>
187+
<ProjectReference Include="..\..\src\DotNetOpenAuth.Mvc\DotNetOpenAuth.Mvc.csproj">
188+
<Project>{9d308ef2-2712-4f83-a14c-18bf08d45526}</Project>
189+
<Name>DotNetOpenAuth.Mvc</Name>
190+
</ProjectReference>
187191
<ProjectReference Include="..\..\src\DotNetOpenAuth.OpenId.RelyingParty.UI\DotNetOpenAuth.OpenId.RelyingParty.UI.csproj">
188192
<Project>{1ED8D424-F8AB-4050-ACEB-F27F4F909484}</Project>
189193
<Name>DotNetOpenAuth.OpenId.RelyingParty.UI</Name>

src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,6 @@
173173
<SpecificVersion>False</SpecificVersion>
174174
<HintPath>..\packages\log4net.2.0.2\lib\net40-full\log4net.dll</HintPath>
175175
</Reference>
176-
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
177-
<Private>True</Private>
178-
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
179-
</Reference>
180176
<Reference Include="NLog, Version=2.1.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
181177
<SpecificVersion>False</SpecificVersion>
182178
<HintPath>..\packages\NLog.2.1.0\lib\net45\NLog.dll</HintPath>
@@ -189,30 +185,6 @@
189185
<HintPath>..\packages\Microsoft.Net.Http.2.2.15\lib\net45\System.Net.Http.Primitives.dll</HintPath>
190186
</Reference>
191187
<Reference Include="System.Net.Http.WebRequest" />
192-
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
193-
<SpecificVersion>False</SpecificVersion>
194-
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.Helpers.dll</HintPath>
195-
</Reference>
196-
<Reference Include="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
197-
<SpecificVersion>False</SpecificVersion>
198-
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.0.0\lib\net45\System.Web.Mvc.dll</HintPath>
199-
</Reference>
200-
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
201-
<SpecificVersion>False</SpecificVersion>
202-
<HintPath>..\packages\Microsoft.AspNet.Razor.3.0.0\lib\net45\System.Web.Razor.dll</HintPath>
203-
</Reference>
204-
<Reference Include="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
205-
<SpecificVersion>False</SpecificVersion>
206-
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.dll</HintPath>
207-
</Reference>
208-
<Reference Include="System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
209-
<SpecificVersion>False</SpecificVersion>
210-
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
211-
</Reference>
212-
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
213-
<SpecificVersion>False</SpecificVersion>
214-
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
215-
</Reference>
216188
<Reference Include="Validation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL">
217189
<SpecificVersion>False</SpecificVersion>
218190
<HintPath>..\packages\Validation.2.0.2.13022\lib\portable-windows8+net40+sl5+windowsphone8\Validation.dll</HintPath>

src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace DotNetOpenAuth.Messaging {
2424
using System.Threading;
2525
using System.Threading.Tasks;
2626
using System.Web;
27-
using System.Web.Mvc;
2827
using System.Xml;
2928
using DotNetOpenAuth.Messaging.Bindings;
3029
using DotNetOpenAuth.Messaging.Reflection;
@@ -410,16 +409,6 @@ public static Uri GetPublicFacingUrl() {
410409
return GetPublicFacingUrl(new HttpRequestWrapper(HttpContext.Current.Request));
411410
}
412411

413-
/// <summary>
414-
/// Wraps a response message as an MVC <see cref="ActionResult"/> so it can be conveniently returned from an MVC controller's action method.
415-
/// </summary>
416-
/// <param name="response">The response message.</param>
417-
/// <returns>An <see cref="ActionResult"/> instance.</returns>
418-
public static ActionResult AsActionResult(this HttpResponseMessage response) {
419-
Requires.NotNull(response, "response");
420-
return new HttpResponseMessageActionResult(response);
421-
}
422-
423412
/// <summary>
424413
/// Wraps an instance of <see cref="HttpRequestBase"/> as an <see cref="HttpRequestMessage"/> instance.
425414
/// </summary>
@@ -2043,33 +2032,5 @@ public int Compare(T x, T y) {
20432032

20442033
#endregion
20452034
}
2046-
2047-
/// <summary>
2048-
/// An MVC <see cref="ActionResult"/> that wraps an <see cref="HttpResponseMessage"/>
2049-
/// </summary>
2050-
private class HttpResponseMessageActionResult : ActionResult {
2051-
/// <summary>
2052-
/// The wrapped response.
2053-
/// </summary>
2054-
private readonly HttpResponseMessage response;
2055-
2056-
/// <summary>
2057-
/// Initializes a new instance of the <see cref="HttpResponseMessageActionResult"/> class.
2058-
/// </summary>
2059-
/// <param name="response">The response.</param>
2060-
internal HttpResponseMessageActionResult(HttpResponseMessage response) {
2061-
Requires.NotNull(response, "response");
2062-
this.response = response;
2063-
}
2064-
2065-
/// <summary>
2066-
/// Enables processing of the result of an action method by a custom type that inherits from the <see cref="T:System.Web.Mvc.ActionResult" /> class.
2067-
/// </summary>
2068-
/// <param name="context">The context in which the result is executed. The context information includes the controller, HTTP content, request context, and route data.</param>
2069-
public override void ExecuteResult(ControllerContext context) {
2070-
// Sadly, MVC doesn't support writing to the response stream asynchronously.
2071-
this.response.SendAsync(context.HttpContext).GetAwaiter().GetResult();
2072-
}
2073-
}
20742035
}
20752036
}
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="log4net" version="2.0.2" targetFramework="net45" />
4-
<package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
5-
<package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
6-
<package id="Microsoft.AspNet.WebPages" version="3.0.0" targetFramework="net45" />
74
<package id="Microsoft.Bcl" version="1.1.3" targetFramework="net45" />
85
<package id="Microsoft.Bcl.Build" version="1.0.10" targetFramework="net45" />
96
<package id="Microsoft.Net.Http" version="2.2.15" targetFramework="net45" />
10-
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
117
<package id="NLog" version="2.1.0" targetFramework="net45" />
128
<package id="Validation" version="2.0.2.13022" targetFramework="net45" />
139
</packages>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.props))\EnlistmentInfo.props" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.props))' != '' " />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
8+
</PropertyGroup>
9+
<Import Project="$(ProjectRoot)tools\DotNetOpenAuth.props" />
10+
<PropertyGroup>
11+
<SchemaVersion>2.0</SchemaVersion>
12+
<ProjectGuid>{9D308EF2-2712-4F83-A14C-18BF08D45526}</ProjectGuid>
13+
<AppDesignerFolder>Properties</AppDesignerFolder>
14+
<AssemblyName>DotNetOpenAuth.Mvc</AssemblyName>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
19+
</PropertyGroup>
20+
<Import Project="$(ProjectRoot)tools\DotNetOpenAuth.Product.props" />
21+
<ItemGroup>
22+
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
23+
<Private>True</Private>
24+
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
25+
</Reference>
26+
<Reference Include="System" />
27+
<Reference Include="System.Core" />
28+
<Reference Include="System.Net.Http" />
29+
<Reference Include="System.Net.Http.Extensions">
30+
<HintPath>..\packages\Microsoft.Net.Http.2.2.15\lib\net45\System.Net.Http.Extensions.dll</HintPath>
31+
</Reference>
32+
<Reference Include="System.Net.Http.Primitives">
33+
<HintPath>..\packages\Microsoft.Net.Http.2.2.15\lib\net45\System.Net.Http.Primitives.dll</HintPath>
34+
</Reference>
35+
<Reference Include="System.Net.Http.WebRequest" />
36+
<Reference Include="System.Web" />
37+
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
38+
<SpecificVersion>False</SpecificVersion>
39+
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.Helpers.dll</HintPath>
40+
</Reference>
41+
<Reference Include="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
42+
<SpecificVersion>False</SpecificVersion>
43+
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.0.0\lib\net45\System.Web.Mvc.dll</HintPath>
44+
</Reference>
45+
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
46+
<SpecificVersion>False</SpecificVersion>
47+
<HintPath>..\packages\Microsoft.AspNet.Razor.3.0.0\lib\net45\System.Web.Razor.dll</HintPath>
48+
</Reference>
49+
<Reference Include="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
50+
<SpecificVersion>False</SpecificVersion>
51+
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.dll</HintPath>
52+
</Reference>
53+
<Reference Include="System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
54+
<SpecificVersion>False</SpecificVersion>
55+
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
56+
</Reference>
57+
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
58+
<SpecificVersion>False</SpecificVersion>
59+
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
60+
</Reference>
61+
<Reference Include="System.Xml.Linq" />
62+
<Reference Include="System.Data.DataSetExtensions" />
63+
<Reference Include="Microsoft.CSharp" />
64+
<Reference Include="System.Data" />
65+
<Reference Include="System.Xml" />
66+
<Reference Include="Validation">
67+
<HintPath>..\packages\Validation.2.0.2.13022\lib\portable-windows8+net40+sl5+windowsphone8\Validation.dll</HintPath>
68+
</Reference>
69+
</ItemGroup>
70+
<ItemGroup>
71+
<Compile Include="MvcExtensions.cs" />
72+
<Compile Include="Properties\AssemblyInfo.cs" />
73+
</ItemGroup>
74+
<ItemGroup>
75+
<None Include="packages.config" />
76+
</ItemGroup>
77+
<ItemGroup>
78+
<ProjectReference Include="..\DotNetOpenAuth.Core\DotNetOpenAuth.Core.csproj">
79+
<Project>{60426312-6ae5-4835-8667-37edea670222}</Project>
80+
<Name>DotNetOpenAuth.Core</Name>
81+
</ProjectReference>
82+
</ItemGroup>
83+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
84+
<Import Project="$(ProjectRoot)tools\DotNetOpenAuth.targets" />
85+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))\EnlistmentInfo.targets" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))' != '' " />
86+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
87+
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" />
88+
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
89+
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
90+
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
91+
</Target>
92+
</Project>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright file="MvcExtensions.cs" company="Andrew Arnott">
3+
// Copyright (c) Andrew Arnott. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------
6+
7+
namespace DotNetOpenAuth.Messaging
8+
{
9+
using System;
10+
using System.Collections.Generic;
11+
using System.Linq;
12+
using System.Net.Http;
13+
using System.Text;
14+
using System.Threading.Tasks;
15+
using System.Web.Mvc;
16+
using DotNetOpenAuth.Messaging;
17+
using Validation;
18+
19+
/// <summary>
20+
/// DotNetOpenAuth extensions for ASP.NET MVC.
21+
/// </summary>
22+
public static class MvcExtensions {
23+
/// <summary>
24+
/// Wraps a response message as an MVC <see cref="ActionResult"/> so it can be conveniently returned from an MVC controller's action method.
25+
/// </summary>
26+
/// <param name="response">The response message.</param>
27+
/// <returns>An <see cref="ActionResult"/> instance.</returns>
28+
public static ActionResult AsActionResult(this HttpResponseMessage response) {
29+
Requires.NotNull(response, "response");
30+
return new HttpResponseMessageActionResult(response);
31+
}
32+
33+
/// <summary>
34+
/// An MVC <see cref="ActionResult"/> that wraps an <see cref="HttpResponseMessage"/>
35+
/// </summary>
36+
private class HttpResponseMessageActionResult : ActionResult {
37+
/// <summary>
38+
/// The wrapped response.
39+
/// </summary>
40+
private readonly HttpResponseMessage response;
41+
42+
/// <summary>
43+
/// Initializes a new instance of the <see cref="HttpResponseMessageActionResult"/> class.
44+
/// </summary>
45+
/// <param name="response">The response.</param>
46+
internal HttpResponseMessageActionResult(HttpResponseMessage response) {
47+
Requires.NotNull(response, "response");
48+
this.response = response;
49+
}
50+
51+
/// <summary>
52+
/// Enables processing of the result of an action method by a custom type that inherits from the <see cref="T:System.Web.Mvc.ActionResult" /> class.
53+
/// </summary>
54+
/// <param name="context">The context in which the result is executed. The context information includes the controller, HTTP content, request context, and route data.</param>
55+
public override void ExecuteResult(ControllerContext context) {
56+
// Sadly, MVC doesn't support writing to the response stream asynchronously.
57+
this.response.SendAsync(context.HttpContext).GetAwaiter().GetResult();
58+
}
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)