-
Notifications
You must be signed in to change notification settings - Fork 167
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
WorkerExtensionStartup registers Middleware before ConfigureFunctionsWebApplication when using Http.AspNetCore #2506
Comments
@swettstein AspNetCore registration is also an extension using the same hook as your example. We offer no ordering control for this way of registering middleware, so this would be a new feature to offer that ability via the attribute route. For now, if you need to control the middleware timing, users will need to register it during |
controlling the order of extension middleware would be a nice feature but there is some complexity there and probably not necessary in this case. the AspNetCore extension doesn't use WorkerExtensionStartup but rather depends on users correctly applying an extension method from FunctionsHostBuilderExtensions. none of the other built-in extensions operate this way so why is this one different? why couldn't the AspNetCore extension be internally smarter about how it gets registered by ensuring that its middleware gets inserted first? |
Keeping this item in the backlog, as it is a valid request/gap, but this is low priority and there are no plans to have this worked on at the moment. |
The reason for this comes down to needing access to the
For the same reason other extensions do not control order of middleware: there is no API for that. The extension only accesses public APIs from our worker assemblies, so it has no more privilege at setting a middleware first than any other extension does. Addressing both of these points would require a non-trivial overhaul of some of our public APIs - which is not a priority at this point. |
Some of it needs access to i agree setting middleware priority would be non-trivial, especially when some of them are anonymous delegates. but what may be easier to do is priority of ultimately if i'm creating an extension that's dependent on another extension, i would like to control the timing/ordering within my extension rather than depending on end users to get it right. |
Description
I have an extension library that automatically registers some middleware for my users. However, these middleware are dependent on the HttpContext existing in the FunctionContext.Items dictionary (put there by FunctionsHttpProxyingMiddleware). When using WorkerExtensionStartup to register these middleware, it appears they are added before ConfigureFunctionsWebApplication adds the proxying middleware and thus will not have access to the HttpContext.
Steps to reproduce
Extension Library Startup Class
Client Application Program.cs
There is a workaround: create an extension method so that users have to register the middleware inside of ConfigureFunctionsWebApplication.
Extension Method:
Program.cs:
The text was updated successfully, but these errors were encountered: