Is it possible to provide a value to an Azure Function from Middleware?

281 Views Asked by At

I have a default Azure function, and some middleware.

What I want is when xml is sent, the middleware parses it into an object, and passes this object to the azure function. The code would look like this:

public class MyMiddleware : IFunctionsWorkerMiddleware
{
    public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next)
    {
        // Get the posted data from the http context
        var theData = context.GetTheIncomingXMLData();
        // Create a new object
        var myComplexObject = ParseXMLToObject(theData);
        // Somehow pass this to the function? 
        context.Items.Add("someObject", myComplexObject); // Don't think this is right

        await next(context);
    }
}

Then my function would be:

[Function("Function1")]
        public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req,
            ComplexObject someObject) // Automatically populated from the middleware
        { ...
}

I've done this kind of thing using value providers in MVC but wondering if you can do it with Azure Functions?

0

There are 0 best solutions below