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 99
1010using System . Web ;
1111using Microsoft . Web . Infrastructure . DynamicModuleHelper ;
12+ using React . TinyIoC ;
1213using React . Web ;
1314using React . Web . TinyIoC ;
1415
@@ -26,10 +27,25 @@ internal static class WebInitializer
2627 /// </summary>
2728 public static void Initialize ( )
2829 {
29- Initializer . Initialize ( ( ) => new HttpContextLifetimeProvider ( ) ) ;
30+ Initializer . Initialize ( AsPerRequestSingleton ) ;
3031 DynamicModuleUtility . RegisterModule ( typeof ( IocPerRequestDisposal ) ) ;
3132 }
3233
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+
3349 /// <summary>
3450 /// Handles disposing per-request IoC instances at the end of the request
3551 /// </summary>
Original file line number Diff line number Diff line change 1111using System . Linq ;
1212using System . Reflection ;
1313using React . TinyIoC ;
14+ using RegisterOptions = React . TinyIoC . TinyIoCContainer . RegisterOptions ;
1415
1516namespace React
1617{
@@ -22,18 +23,24 @@ public static class Initializer
2223 /// <summary>
2324 /// Intialise ReactJS.NET
2425 /// </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 )
2630 {
27- InitializeIoC ( requestLifetimeProviderFactory ) ;
31+ InitializeIoC ( requestLifetimeRegistration ) ;
2832 }
2933
3034 /// <summary>
3135 /// Initialises the IoC container by finding all <see cref="IAssemblyRegistration"/>
3236 /// implementations and calling their <see cref="IAssemblyRegistration.Register"/> methods.
3337 /// </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 )
3542 {
36- TinyIoCExtensions . RequestLifetimeProviderFactory = requestLifetimeProviderFactory ;
43+ TinyIoCExtensions . AsRequestLifetime = requestLifetimeRegistration ;
3744 var types = AppDomain . CurrentDomain . GetAssemblies ( )
3845 // Only bother checking React assemblies
3946 . Where ( IsReactAssembly )
Original file line number Diff line number Diff line change 99
1010using System ;
1111using React . TinyIoC ;
12+ using RegisterOptions = React . TinyIoC . TinyIoCContainer . RegisterOptions ;
1213
1314namespace React
1415{
@@ -20,7 +21,7 @@ public static class TinyIoCExtensions
2021 /// <summary>
2122 /// Gets or sets the factory used to create per-request lifetime providers
2223 /// </summary>
23- internal static Func < TinyIoCContainer . ITinyIoCObjectLifetimeProvider > RequestLifetimeProviderFactory { private get ; set ; }
24+ internal static Func < RegisterOptions , RegisterOptions > AsRequestLifetime { private get ; set ; }
2425
2526 /// <summary>
2627 /// Registers a class in IoC that uses a singleton per "request". This is generally in the
@@ -30,20 +31,16 @@ public static class TinyIoCExtensions
3031 /// <returns>The class registration (fluent interface)</returns>
3132 public static TinyIoCContainer . RegisterOptions AsPerRequestSingleton ( this TinyIoCContainer . RegisterOptions registerOptions )
3233 {
33- if ( RequestLifetimeProviderFactory == null )
34+ if ( AsRequestLifetime == null )
3435 {
3536 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 " +
3738 "assembly registrations to work. Please ensure you are calling " +
3839 "React.Initializer.Initialize() before using any ReactJS.NET functionality."
3940 ) ;
4041 }
4142
42- return TinyIoCContainer . RegisterOptions . ToCustomLifetimeManager (
43- registerOptions ,
44- RequestLifetimeProviderFactory ( ) ,
45- "per request singleton"
46- ) ;
43+ return AsRequestLifetime ( registerOptions ) ;
4744 }
4845 }
4946}
You can’t perform that action at this time.
0 commit comments