1111using Microsoft . AspNetCore . Builder ;
1212using Microsoft . AspNetCore . Hosting ;
1313using Microsoft . AspNetCore . Http ;
14- using Microsoft . Extensions . PlatformAbstractions ;
1514using React . Exceptions ;
1615using React . TinyIoC ;
1716using Microsoft . Extensions . DependencyInjection ;
17+ #if ! NET451
18+ using Microsoft . Extensions . Caching . Memory ;
19+ #endif
1820
1921namespace React . AspNet
2022{
@@ -38,7 +40,7 @@ public static IApplicationBuilder UseReact(
3840 {
3941 EnsureServicesRegistered ( app ) ;
4042
41- React . AssemblyRegistration . Container . Register ( app . ApplicationServices . GetRequiredService < IHostingEnvironment > ( ) ) ;
43+ RegisterAspNetServices ( React . AssemblyRegistration . Container , app . ApplicationServices ) ;
4244
4345 Initializer . Initialize ( registerOptions => AsPerRequestSingleton (
4446 app . ApplicationServices . GetService < IHttpContextAccessor > ( ) ,
@@ -82,5 +84,19 @@ private static void EnsureServicesRegistered(IApplicationBuilder app)
8284 throw new ReactNotInitialisedException ( "Please call app.AddReact() before app.UseReact()." ) ;
8385 }
8486 }
87+
88+ /// <summary>
89+ /// Registers required ASP.NET services in ReactJS.NET's TinyIoC container. This is used
90+ /// for ASP.NET services that are required by ReactJS.NET.
91+ /// </summary>
92+ /// <param name="container">ReactJS.NET dependency injection container</param>
93+ /// <param name="services">ASP.NET dependency injection container</param>
94+ private static void RegisterAspNetServices ( TinyIoCContainer container , IServiceProvider services )
95+ {
96+ container . Register ( services . GetRequiredService < IHostingEnvironment > ( ) ) ;
97+ #if ! NET451
98+ container . Register ( services . GetRequiredService < IMemoryCache > ( ) ) ;
99+ #endif
100+ }
85101 }
86102}
0 commit comments