CorrelationId icon indicating copy to clipboard operation
CorrelationId copied to clipboard

Usage in Azure Functions

Open alastairtree opened this issue 3 years ago • 0 comments

Hi,

Thanks for this library, it is great.

I had a use case for it in Azure Functions where there is no middleware pipeline to hook into, so I used the library and added a small class that emulates the key bits of the middleware from this project but allowing it to be called as a wrapper function on a single HTTP Request in isolation.

You can see the code in this gist and you use it like this:

public MyFunc(HttpCorrelation http)
{
      this.http = http;
}

[FunctionName(nameof("MyFunc"))]
public async Task<IActionResult> Put([HttpTrigger(AuthorizationLevel.Function, "put", Route = "endpoint")]
            HttpRequest req)
{
    return await http.ExecuteFunction(req, async () =>
    {
          // Do stuff ...
         return new AcceptedResult();
    });
}

Just posting it here in case it is of use to anyone or you wanted to adopt a version of it.

alastairtree avatar Dec 30 '20 08:12 alastairtree