-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add support for isolated Azure Functions #318
Comments
Would it make more sense to modify the abstractions to use |
Since none of the existing frameworks we support (in-process Azure Functions, isolated Azure Functions, plain old ASP.NET Core) represent incoming requests and and outgoing responses using these types, forcing everything to use this would ensure that we would invariably end up allocating additional objects. (We'd need to build an One of our medium term goals is to get to a much lower allocation implementation of So although today's Menes is very allocation-heavy, and adding one more per-request allocation isn't going to change much, it would directly conflict with where we're trying to get to. There's also a possible "lowest common denominator" problem. An advantage of writing per-host adapters is that we can make it work in a way that is as close to optimal for that framework as possible. If instead everything goes via some intermediate representation, that can become harder. Also, these types are mainly used client side. Trying to dredge up information from the depths of my memory I think there may once have been a point where the ASP.NET (not Core) WebAPI libraries did use these types to represent requests on the server (giving symmetry between the client and server representations of requests and responses) that's not how ASP.NET Core (or either of the Functions host models) works today. So an ASP.NET Core app might use an Also, I'm not sure this would save us very much. We'd still end up writing per-host adapters. And also a separate adaptation layer between these types and what Menes needs. We currently have a prototype on a branch for enabling this in which we've moved the common code up into a core library, enabling everything that can be shared to be shared, with framework-specific adapter types needing to contain only the fairly small amount of code that is specific to the framework. |
The isolated worked process model available for non-LTS versions of .NET (and currently slated to be the main model even for LTS versions from .NET 8.0 on) introduces some changes to the programming model. Most notably, Http Triggers no longer get access to ASP.NET Core representations of requests or responses. Instead, the
Microsoft.Azure.Functions.Worker
libraries supplyHttpRequestData
andHttpResponseData
wrapper types, and a functions-specific pipeline model.This means that neither the original
IOpenApiHost<HttpRequest, IActionResult>
implementation available when you calledservices.AddOpenApiActionResultHosting<TContext>()>
nor theIOpenApiHost<HttpRequest, IHttpResponseResult>
version available withservices.AddOpenApiAspNetPipelineHosting<TContext>()
is applicable.We need
IOpenApiHost<HttpRequestData, Something>
, because theHttpRequest
(common to both of the existing implementations) is no longer available. TheSomething
can't beHttpResponseData
, even though that is ultimately the response type, because you can't construct anHttpResponseData
directly. So we will need to follow a similar pattern to the one we introduced for the direct pipeline mode, so most likely anIHttpResponseDataResult
.We want the usage model to look something like this:
and
HandleRequestAsync
here would be an extension method that used the underlying host interface and dealt with getting theHttpRequestResponse
from theIHttpResponseDataResult
:Our implementation of
IOpenApiHost<TRequest, TResponse>
is already generic, so to enable this we just need to supply implementations of the various types that is depends on.We would need an implementation of
IOpenApiParameterBuilder<HttpRequestData>
. the existingIOpenApiParameterBuilder<HttpRequest>
implementation,Menes.Internal.HttpRequestParameterBuilder
in theMenes.Hosting.AspNetCore
project currently contains a mixture of logic that is specific toHttpRequest
and which would be equally applicable toHttpRequestData
. We should refactor this so that the common behaviour is in a base class inMenes.Hosting
, with the currentMenes.Hosting.AspNetCore
and a newMenes.Hosting.FunctionsWorker
containing just the request-type-specific behaviour.We would also need an
IOpenApiResultBuilder<IHttpResponseDataResult>
implementation. This should require slightly less rework, because we already haveIOpenApiResultBuilder<IActionResult>
andIOpenApiResultBuilder<IHttpResponseResult>
implementations (OpenApiActionResultBuilder
andOpenApiHttpResponseResultBuilder
respectively) that both derive fromOpenApiResultBuilder<TResult>
. These already split generic behaviour out from response-specific behaviour. (That's because whereas we only had a single input type before, we already had two different result types.)We would also need two
IResponseOutputBuilder<IHttpResponseDataResult>
implementations, one for POCOs, and one for OpenApiResults. Again, because this concerns response types, the library is already reasonably well factored—there are equivalent pairs of implementations of this forIActionResult
andIHttpResponseResult
already, and these pairs derive from a pair of base classes:PocoOutputBuilder<TResult>
andOpenApiResultOutputBuilder<TResult>
. We should be able to derive two more types from these to define ones that work withIHttpResponseDataResult
.We would also need to ensure that the
OpenApiWebHostManager
type that provides the ability to host services in-process works with the new approach.So in summary:
IOpenApiParameterBuilder<HttpRequestData>
IOpenApiResultBuilder<IHttpResponseDataResult>
IResponseOutputBuilder<IHttpResponseDataResult>
for POCOIResponseOutputBuilder<IHttpResponseDataResult>
forOpenApiResult
The text was updated successfully, but these errors were encountered: