Skip to content

Commit

Permalink
Remove requirement for service provider to be returned in ConfigureSe…
Browse files Browse the repository at this point in the history
…rvices

None of the .NET core docs reference this, and it is only needed for this one check.

See #601
  • Loading branch information
Dustin Masters committed Nov 4, 2018
1 parent df1af1e commit 50737e7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
19 changes: 2 additions & 17 deletions src/React.AspNet.Middleware/ReactBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

Expand Down Expand Up @@ -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<IHttpContextAccessor>(),
app.ApplicationServices.GetService<IHttpContextAccessor>(),
registerOptions
));

Expand Down Expand Up @@ -79,19 +77,6 @@ TinyIoCContainer.RegisterOptions registerOptions
);
}

/// <summary>
/// Ensures React services have been registered in the ASP.NET dependency injection container.
/// </summary>
/// <param name="app">ASP.NET application builder</param>
private static void EnsureServicesRegistered(IApplicationBuilder app)
{
var registrations = app.ApplicationServices.GetService<HttpContextLifetimeProvider.PerRequestRegistrations>();
if (registrations == null)
{
throw new ReactNotInitialisedException("Please call services.AddReact() before app.UseReact().");
}
}

/// <summary>
/// Registers required ASP.NET services in ReactJS.NET's TinyIoC container. This is used
/// for ASP.NET services that are required by ReactJS.NET.
Expand Down
4 changes: 2 additions & 2 deletions src/React.Sample.Webpack.CoreMvc/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

// 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.
Expand Down

0 comments on commit 50737e7

Please sign in to comment.