I'm looking for a way to add a standard azure function to every azure function project. This is a requirement of our environment that all APIs have a health endpoint, so to make it consistent I want to write it once and use it many.
My idea is to have the function in a class library and then reference it in my azure function project, but it doesn't seem to work. For each thing I have tried, only the functions in my azure function project appear.
Here is my shared function class, written in a separate referenced class library:
public class HealthEndpointFunctions
{
[FunctionName("Health")]
public async Task<IActionResult> Health(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "health")] HttpRequest req)
{
return new OkResult();
}
}
So far I have tried:
- Just adding a project reference hoping it would be identified but the function is not listed.
- Adding a function class to the azure function project that uses this as a base class
public class Function1 : HealthEndpointFunctions
{
[FunctionName("Function1")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req)
{
return new OkObjectResult("OKely dokely");
}
}
... in this case, only Function1
in the derived class is available
Feels to me that there must be some configuration in the azure function project to enable this, if indeed it is even possible.
Also welcome to suggested other approaches.