forked from reactjs/React.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssemblyRegistration.cs
More file actions
72 lines (66 loc) · 2.37 KB
/
Copy pathAssemblyRegistration.cs
File metadata and controls
72 lines (66 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright (c) 2014-Present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
using System.Diagnostics;
using System.Web;
using System.Web.Caching;
using System.Web.Hosting;
using React.TinyIoC;
namespace React.Web
{
/// <summary>
/// Handles registration of ReactJS.NET components that are only applicable
/// in the context of an ASP.NET web application.
/// </summary>
public class AssemblyRegistration : IAssemblyRegistration
{
/// <summary>
/// Registers components in the React IoC container
/// </summary>
/// <param name="container">Container to register components in</param>
public void Register(TinyIoCContainer container)
{
if (!IsInAspNet())
{
Trace.WriteLine(
"Warning: The current application references React.Web but is not an " +
"ASP.NET Web Application. Not running webapp IoC initialisation!"
);
return;
}
// Unique per request
container.Register<IFileSystem, AspNetFileSystem>().AsPerRequestSingleton();
container.Register<IBabelHandler, BabelHandler>().AsPerRequestSingleton();
// Mono for Mac OS does not properly handle caching
// TODO: Remove this once https://bugzilla.xamarin.com/show_bug.cgi?id=19071 is fixed
if (SystemEnvironmentUtils.IsRunningOnMac())
{
container.Register<ICache, NullCache>().AsSingleton();
}
else
{
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>
/// Determines if the current application is running in the context of an ASP.NET
/// Web Application
/// </summary>
/// <returns><c>true</c> if in an ASP.NET web app; <c>false</c> otherwise</returns>
public static bool IsInAspNet()
{
return HostingEnvironment.IsHosted;
}
}
}