Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The requirements of the class to create a custom middleware are not well documented #11443

Closed
meziantou opened this issue Mar 17, 2019 — with docs.microsoft.com · 4 comments · Fixed by #12895
Closed
Labels
Pri1 Source - Docs.ms Docs Customer feedback via GitHub Issue
Milestone

Comments

Copy link
Contributor

What are the exact requirements for writing a custom middleware as a class?

  • A constructor with a single parameter of type RequestDelegate
  • A method named Invoke or InvokeAsync
    • must return a Task?
    • must have a parameter of type HttpContext

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@dotnet-bot dotnet-bot added the Source - Docs.ms Docs Customer feedback via GitHub Issue label Mar 17, 2019
@Rick-Anderson Rick-Anderson added this to the Backlog milestone Mar 17, 2019
@Rick-Anderson
Copy link
Contributor

I agree. That should be explained in the first section.

Copy link

APIWT commented Mar 29, 2019

This brings up an interesting point: Should there be an interface for implementing middleware?

@meziantou
Copy link
Contributor Author

There is already the interface IMiddleware. But you are not required to use it.

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/extensibility?view=aspnetcore-2.2

@AgentFire
Copy link

I've created a request for it: #34730

You should be inclined to use the interface, im my opinion. The old way should start to be getting deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pri1 Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants