Skip to content

Commit 50737e7

Browse files
author
Dustin Masters
committed
Remove requirement for service provider to be returned in ConfigureServices
None of the .NET core docs reference this, and it is only needed for this one check. See reactjs#601
1 parent df1af1e commit 50737e7

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

src/React.AspNet.Middleware/ReactBuilderExtensions.cs

+2-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* All rights reserved.
44
*
55
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
6+
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

@@ -40,12 +40,10 @@ public static IApplicationBuilder UseReact(
4040
BabelFileOptions fileOptions = null
4141
)
4242
{
43-
EnsureServicesRegistered(app);
44-
4543
RegisterAspNetServices(React.AssemblyRegistration.Container, app.ApplicationServices);
4644

4745
Initializer.Initialize(registerOptions => AsPerRequestSingleton(
48-
app.ApplicationServices.GetService<IHttpContextAccessor>(),
46+
app.ApplicationServices.GetService<IHttpContextAccessor>(),
4947
registerOptions
5048
));
5149

@@ -79,19 +77,6 @@ TinyIoCContainer.RegisterOptions registerOptions
7977
);
8078
}
8179

82-
/// <summary>
83-
/// Ensures React services have been registered in the ASP.NET dependency injection container.
84-
/// </summary>
85-
/// <param name="app">ASP.NET application builder</param>
86-
private static void EnsureServicesRegistered(IApplicationBuilder app)
87-
{
88-
var registrations = app.ApplicationServices.GetService<HttpContextLifetimeProvider.PerRequestRegistrations>();
89-
if (registrations == null)
90-
{
91-
throw new ReactNotInitialisedException("Please call services.AddReact() before app.UseReact().");
92-
}
93-
}
94-
9580
/// <summary>
9681
/// Registers required ASP.NET services in ReactJS.NET's TinyIoC container. This is used
9782
/// for ASP.NET services that are required by ReactJS.NET.

src/React.Sample.Webpack.CoreMvc/Startup.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Startup(IConfiguration configuration)
2020
public IConfiguration Configuration { get; }
2121

2222
// This method gets called by the runtime. Use this method to add services to the container.
23-
public IServiceProvider ConfigureServices(IServiceCollection services)
23+
public void ConfigureServices(IServiceCollection services)
2424
{
2525
services.AddMvc();
2626

@@ -31,7 +31,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
3131
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
3232

3333
// Build the intermediate service provider then return it
34-
return services.BuildServiceProvider();
34+
services.BuildServiceProvider();
3535
}
3636

3737
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

0 commit comments

Comments
 (0)