From 50737e740244c2b5c7bdf2c61031271866635cc0 Mon Sep 17 00:00:00 2001 From: Dustin Masters Date: Sat, 3 Nov 2018 23:01:56 -0700 Subject: [PATCH] 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 #601 --- .../ReactBuilderExtensions.cs | 19 ++----------------- src/React.Sample.Webpack.CoreMvc/Startup.cs | 4 ++-- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/React.AspNet.Middleware/ReactBuilderExtensions.cs b/src/React.AspNet.Middleware/ReactBuilderExtensions.cs index d89091b56..55798c24c 100644 --- a/src/React.AspNet.Middleware/ReactBuilderExtensions.cs +++ b/src/React.AspNet.Middleware/ReactBuilderExtensions.cs @@ -3,7 +3,7 @@ * 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 + * 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. */ @@ -40,12 +40,10 @@ public static IApplicationBuilder UseReact( BabelFileOptions fileOptions = null ) { - EnsureServicesRegistered(app); - RegisterAspNetServices(React.AssemblyRegistration.Container, app.ApplicationServices); Initializer.Initialize(registerOptions => AsPerRequestSingleton( - app.ApplicationServices.GetService(), + app.ApplicationServices.GetService(), registerOptions )); @@ -79,19 +77,6 @@ TinyIoCContainer.RegisterOptions registerOptions ); } - /// - /// Ensures React services have been registered in the ASP.NET dependency injection container. - /// - /// ASP.NET application builder - private static void EnsureServicesRegistered(IApplicationBuilder app) - { - var registrations = app.ApplicationServices.GetService(); - if (registrations == null) - { - throw new ReactNotInitialisedException("Please call services.AddReact() before app.UseReact()."); - } - } - /// /// Registers required ASP.NET services in ReactJS.NET's TinyIoC container. This is used /// for ASP.NET services that are required by ReactJS.NET. diff --git a/src/React.Sample.Webpack.CoreMvc/Startup.cs b/src/React.Sample.Webpack.CoreMvc/Startup.cs index 659c7a232..fdb440cf4 100644 --- a/src/React.Sample.Webpack.CoreMvc/Startup.cs +++ b/src/React.Sample.Webpack.CoreMvc/Startup.cs @@ -20,7 +20,7 @@ public Startup(IConfiguration configuration) public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. - public IServiceProvider ConfigureServices(IServiceCollection services) + public void ConfigureServices(IServiceCollection services) { services.AddMvc(); @@ -31,7 +31,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services) services.AddSingleton(); // Build the intermediate service provider then return it - return services.BuildServiceProvider(); + services.BuildServiceProvider(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.