Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Make RequestServicesContainerMiddleware the first middleware in the pipeline #653

Closed
@weidazhao

Description

@weidazhao

When we add a middleware through IStartupFilter, it will be added before RequestServicesContainerMiddleware in the pipeline (see the impl at https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs#L163) Therefore, the middleware won't be able to get any scoped service instance from HttpContext.RequestServices since RequestServices is not constructed by RequestServicesContainerMiddleware yet at the moment.

This could be fixed by ensuring RequestServicesContainerMiddleware always to be the first middleware in the pipeline. A possible fix is to move https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs#L202 to https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs#L218.

For more context and details, check out weidazhao/Hosting#8.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions