Skip to content

Commit 89011df

Browse files
committedNov 10, 2017
Resolve ASP.NET environments without HTTP contexts
1 parent 2648b4c commit 89011df

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed
 

‎src/React.Web/AspNetCache.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System;
1111
using System.Collections.Generic;
1212
using System.Linq;
13-
using System.Web;
1413
using System.Web.Caching;
1514

1615
namespace React.Web
@@ -28,10 +27,10 @@ public class AspNetCache : ICache
2827
/// <summary>
2928
/// Initializes a new instance of the <see cref="AspNetCache"/> class.
3029
/// </summary>
31-
/// <param name="context">The HTTP context</param>
32-
public AspNetCache(HttpContextBase context)
30+
/// <param name="cache">The Web application cache</param>
31+
public AspNetCache(Cache cache)
3332
{
34-
_cache = context.Cache;
33+
_cache = cache;
3534
}
3635

3736
/// <summary>
@@ -62,8 +61,9 @@ public AspNetCache(HttpContextBase context)
6261
/// will be cleared automatically
6362
/// </param>
6463
public void Set<T>(
65-
string key, T data,
66-
TimeSpan slidingExpiration,
64+
string key,
65+
T data,
66+
TimeSpan slidingExpiration,
6767
IEnumerable<string> cacheDependencyFiles = null
6868
)
6969
{

‎src/React.Web/AspNetFileSystem.cs

+2-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
using System.Web;
10+
using System.Web.Hosting;
1111

1212
namespace React.Web
1313
{
@@ -17,28 +17,14 @@ namespace React.Web
1717
/// </summary>
1818
public class AspNetFileSystem : FileSystemBase
1919
{
20-
/// <summary>
21-
/// The ASP.NET server utilities
22-
/// </summary>
23-
private readonly HttpServerUtilityBase _serverUtility;
24-
25-
/// <summary>
26-
/// Initializes a new instance of the <see cref="AspNetFileSystem"/> class.
27-
/// </summary>
28-
/// <param name="serverUtility">The server utility.</param>
29-
public AspNetFileSystem(HttpServerUtilityBase serverUtility)
30-
{
31-
_serverUtility = serverUtility;
32-
}
33-
3420
/// <summary>
3521
/// Converts a path from an application relative path (~/...) to a full filesystem path
3622
/// </summary>
3723
/// <param name="relativePath">App-relative path of the file</param>
3824
/// <returns>Full path of the file</returns>
3925
public override string MapPath(string relativePath)
4026
{
41-
return _serverUtility.MapPath(relativePath);
27+
return HostingEnvironment.MapPath(relativePath);
4228
}
4329
}
4430
}

‎src/React.Web/AssemblyRegistration.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
using System.Diagnostics;
1111
using System.Web;
12+
using System.Web.Caching;
1213
using System.Web.Hosting;
1314
using React.TinyIoC;
1415

@@ -47,14 +48,15 @@ public void Register(TinyIoCContainer container)
4748
}
4849
else
4950
{
50-
container.Register<ICache, AspNetCache>().AsPerRequestSingleton();
51+
container.Register<ICache, AspNetCache>().AsPerRequestSingleton();
5152
}
5253

5354
// Wrappers for built-in objects
5455
container.Register<HttpContextBase>((c, o) => new HttpContextWrapper(HttpContext.Current));
5556
container.Register<HttpServerUtilityBase>((c, o) => c.Resolve<HttpContextBase>().Server);
5657
container.Register<HttpRequestBase>((c, o) => c.Resolve<HttpContextBase>().Request);
5758
container.Register<HttpResponseBase>((c, o) => c.Resolve<HttpContextBase>().Response);
59+
container.Register<Cache>((c, o) => HttpRuntime.Cache);
5860
}
5961

6062
/// <summary>

0 commit comments

Comments
 (0)