File tree Expand file tree Collapse file tree 3 files changed +33
-13
lines changed Expand file tree Collapse file tree 3 files changed +33
-13
lines changed Original file line number Diff line number Diff line change 9
9
10
10
using System . Web ;
11
11
using Microsoft . Web . Infrastructure . DynamicModuleHelper ;
12
+ using React . TinyIoC ;
12
13
using React . Web ;
13
14
using React . Web . TinyIoC ;
14
15
@@ -26,10 +27,25 @@ internal static class WebInitializer
26
27
/// </summary>
27
28
public static void Initialize ( )
28
29
{
29
- Initializer . Initialize ( ( ) => new HttpContextLifetimeProvider ( ) ) ;
30
+ Initializer . Initialize ( AsPerRequestSingleton ) ;
30
31
DynamicModuleUtility . RegisterModule ( typeof ( IocPerRequestDisposal ) ) ;
31
32
}
32
33
34
+ /// <summary>
35
+ /// Registers a class such that every ASP.NET web request has a single instance of it.
36
+ /// Instances will be stored in HttpContext.
37
+ /// </summary>
38
+ /// <param name="registerOptions">Registration options</param>
39
+ /// <returns>Registration options (for chaining)</returns>
40
+ private static TinyIoCContainer . RegisterOptions AsPerRequestSingleton ( TinyIoCContainer . RegisterOptions registerOptions )
41
+ {
42
+ return TinyIoCContainer . RegisterOptions . ToCustomLifetimeManager (
43
+ registerOptions ,
44
+ new HttpContextLifetimeProvider ( ) ,
45
+ "per request singleton"
46
+ ) ;
47
+ }
48
+
33
49
/// <summary>
34
50
/// Handles disposing per-request IoC instances at the end of the request
35
51
/// </summary>
Original file line number Diff line number Diff line change 11
11
using System . Linq ;
12
12
using System . Reflection ;
13
13
using React . TinyIoC ;
14
+ using RegisterOptions = React . TinyIoC . TinyIoCContainer . RegisterOptions ;
14
15
15
16
namespace React
16
17
{
@@ -22,18 +23,24 @@ public static class Initializer
22
23
/// <summary>
23
24
/// Intialise ReactJS.NET
24
25
/// </summary>
25
- public static void Initialize ( Func < TinyIoCContainer . ITinyIoCObjectLifetimeProvider > requestLifetimeProviderFactory )
26
+ /// <param name="requestLifetimeRegistration">
27
+ /// A function used to register IoC components with a per-request lifetime
28
+ /// </param>
29
+ public static void Initialize ( Func < RegisterOptions , RegisterOptions > requestLifetimeRegistration )
26
30
{
27
- InitializeIoC ( requestLifetimeProviderFactory ) ;
31
+ InitializeIoC ( requestLifetimeRegistration ) ;
28
32
}
29
33
30
34
/// <summary>
31
35
/// Initialises the IoC container by finding all <see cref="IAssemblyRegistration"/>
32
36
/// implementations and calling their <see cref="IAssemblyRegistration.Register"/> methods.
33
37
/// </summary>
34
- private static void InitializeIoC ( Func < TinyIoCContainer . ITinyIoCObjectLifetimeProvider > requestLifetimeProviderFactory )
38
+ /// <param name="requestLifetimeRegistration">
39
+ /// A function used to register IoC components with a per-request lifetime
40
+ /// </param>
41
+ private static void InitializeIoC ( Func < RegisterOptions , RegisterOptions > requestLifetimeRegistration )
35
42
{
36
- TinyIoCExtensions . RequestLifetimeProviderFactory = requestLifetimeProviderFactory ;
43
+ TinyIoCExtensions . AsRequestLifetime = requestLifetimeRegistration ;
37
44
var types = AppDomain . CurrentDomain . GetAssemblies ( )
38
45
// Only bother checking React assemblies
39
46
. Where ( IsReactAssembly )
Original file line number Diff line number Diff line change 9
9
10
10
using System ;
11
11
using React . TinyIoC ;
12
+ using RegisterOptions = React . TinyIoC . TinyIoCContainer . RegisterOptions ;
12
13
13
14
namespace React
14
15
{
@@ -20,7 +21,7 @@ public static class TinyIoCExtensions
20
21
/// <summary>
21
22
/// Gets or sets the factory used to create per-request lifetime providers
22
23
/// </summary>
23
- internal static Func < TinyIoCContainer . ITinyIoCObjectLifetimeProvider > RequestLifetimeProviderFactory { private get ; set ; }
24
+ internal static Func < RegisterOptions , RegisterOptions > AsRequestLifetime { private get ; set ; }
24
25
25
26
/// <summary>
26
27
/// Registers a class in IoC that uses a singleton per "request". This is generally in the
@@ -30,20 +31,16 @@ public static class TinyIoCExtensions
30
31
/// <returns>The class registration (fluent interface)</returns>
31
32
public static TinyIoCContainer . RegisterOptions AsPerRequestSingleton ( this TinyIoCContainer . RegisterOptions registerOptions )
32
33
{
33
- if ( RequestLifetimeProviderFactory == null )
34
+ if ( AsRequestLifetime == null )
34
35
{
35
36
throw new Exception (
36
- "RequestLifetimeProviderFactory needs to be set for per-request ReactJS.NET " +
37
+ "AsRequestLifetime needs to be set for per-request ReactJS.NET " +
37
38
"assembly registrations to work. Please ensure you are calling " +
38
39
"React.Initializer.Initialize() before using any ReactJS.NET functionality."
39
40
) ;
40
41
}
41
42
42
- return TinyIoCContainer . RegisterOptions . ToCustomLifetimeManager (
43
- registerOptions ,
44
- RequestLifetimeProviderFactory ( ) ,
45
- "per request singleton"
46
- ) ;
43
+ return AsRequestLifetime ( registerOptions ) ;
47
44
}
48
45
}
49
46
}
You can’t perform that action at this time.
0 commit comments