Skip to content

Commit 811bc67

Browse files
committed
Ensure request services middleware is registered before React middleware.
1 parent 0d29c7f commit 811bc67

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/React.AspNet/HttpContextLifetimeProvider.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ private PerRequestRegistrations Registrations
5757
{
5858
get
5959
{
60-
var registrations = HttpContext.RequestServices.GetService<PerRequestRegistrations>();
60+
var requestServices = HttpContext.RequestServices;
61+
if (requestServices == null)
62+
{
63+
throw new ReactNotInitialisedException(
64+
"ASP.NET request services have not been initialised correctly. Please " +
65+
"ensure you are calling app.UseRequestServices() before app.UseReact()."
66+
);
67+
}
68+
var registrations = requestServices.GetService<PerRequestRegistrations>();
6169
if (registrations == null)
6270
{
6371
throw new ReactNotInitialisedException(

0 commit comments

Comments
 (0)