Skip to content

Resolve ASP.NET environments without HTTP contexts #449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/React.Web/AspNetCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;

namespace React.Web
Expand All @@ -28,10 +27,10 @@ public class AspNetCache : ICache
/// <summary>
/// Initializes a new instance of the <see cref="AspNetCache"/> class.
/// </summary>
/// <param name="context">The HTTP context</param>
public AspNetCache(HttpContextBase context)
/// <param name="cache">The Web application cache</param>
public AspNetCache(Cache cache)
{
_cache = context.Cache;
_cache = cache;
}

/// <summary>
Expand Down Expand Up @@ -62,8 +61,9 @@ public AspNetCache(HttpContextBase context)
/// will be cleared automatically
/// </param>
public void Set<T>(
string key, T data,
TimeSpan slidingExpiration,
string key,
T data,
TimeSpan slidingExpiration,
IEnumerable<string> cacheDependencyFiles = null
)
{
Expand Down
18 changes: 2 additions & 16 deletions src/React.Web/AspNetFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

using System.Web;
using System.Web.Hosting;

namespace React.Web
{
Expand All @@ -17,28 +17,14 @@ namespace React.Web
/// </summary>
public class AspNetFileSystem : FileSystemBase
{
/// <summary>
/// The ASP.NET server utilities
/// </summary>
private readonly HttpServerUtilityBase _serverUtility;

/// <summary>
/// Initializes a new instance of the <see cref="AspNetFileSystem"/> class.
/// </summary>
/// <param name="serverUtility">The server utility.</param>
public AspNetFileSystem(HttpServerUtilityBase serverUtility)
{
_serverUtility = serverUtility;
}

/// <summary>
/// Converts a path from an application relative path (~/...) to a full filesystem path
/// </summary>
/// <param name="relativePath">App-relative path of the file</param>
/// <returns>Full path of the file</returns>
public override string MapPath(string relativePath)
{
return _serverUtility.MapPath(relativePath);
return HostingEnvironment.MapPath(relativePath);
}
}
}
4 changes: 3 additions & 1 deletion src/React.Web/AssemblyRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using System.Diagnostics;
using System.Web;
using System.Web.Caching;
using System.Web.Hosting;
using React.TinyIoC;

Expand Down Expand Up @@ -47,14 +48,15 @@ public void Register(TinyIoCContainer container)
}
else
{
container.Register<ICache, AspNetCache>().AsPerRequestSingleton();
container.Register<ICache, AspNetCache>().AsPerRequestSingleton();
}

// Wrappers for built-in objects
container.Register<HttpContextBase>((c, o) => new HttpContextWrapper(HttpContext.Current));
container.Register<HttpServerUtilityBase>((c, o) => c.Resolve<HttpContextBase>().Server);
container.Register<HttpRequestBase>((c, o) => c.Resolve<HttpContextBase>().Request);
container.Register<HttpResponseBase>((c, o) => c.Resolve<HttpContextBase>().Response);
container.Register<Cache>((c, o) => HttpRuntime.Cache);
}

/// <summary>
Expand Down