forked from reactjs/React.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTinyIoCExtensions.cs
More file actions
46 lines (42 loc) · 1.51 KB
/
TinyIoCExtensions.cs
File metadata and controls
46 lines (42 loc) · 1.51 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
/*
* Copyright (c) 2014-2015, 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;
using React.TinyIoC;
using RegisterOptions = React.TinyIoC.TinyIoCContainer.RegisterOptions;
namespace React
{
/// <summary>
/// ReactJS.NET extensions to TinyIoC
/// </summary>
public static class TinyIoCExtensions
{
/// <summary>
/// Gets or sets the factory used to create per-request lifetime providers
/// </summary>
internal static Func<RegisterOptions, RegisterOptions> AsRequestLifetime { private get; set; }
/// <summary>
/// Registers a class in IoC that uses a singleton per "request". This is generally in the
/// context of a web request.
/// </summary>
/// <param name="registerOptions">Class registration options</param>
/// <returns>The class registration (fluent interface)</returns>
public static TinyIoCContainer.RegisterOptions AsPerRequestSingleton(this TinyIoCContainer.RegisterOptions registerOptions)
{
if (AsRequestLifetime == null)
{
throw new Exception(
"AsRequestLifetime needs to be set for per-request ReactJS.NET " +
"assembly registrations to work. Please ensure you are calling " +
"React.Initializer.Initialize() before using any ReactJS.NET functionality."
);
}
return AsRequestLifetime(registerOptions);
}
}
}