如何围绕差异解决方案共享Azure功能



我在一个具有不同功能的应用程序中工作。每个功能应用都有自己的VS解决方案,现在我必须为每个功能应用添加健康检查。基本上是这样一个功能:

public class HealthFunction
{
private readonly HealthCheckService _healthCheckService;
public HealthFunction(HealthCheckService healthCheck)
{
_healthCheckService = healthCheck;
}
[FunctionName("health")]
public async Task<IActionResult> Health(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "health")]
HttpRequest req,
ILogger log)
{
log.Log(LogLevel.Information, "Received health request");
var status = await _healthCheckService.CheckHealthAsync();
return new OkObjectResult(Enum.GetName(typeof(HealthStatus), status.Status));
}
}

是否有某种方法可以在类似nuget的包中共享此HealthFunction?还是别的什么?

基本上,函数应用程序是基于文件夹结构和function.json文件的存在,在这些文件中定义了函数触发器和绑定,以在函数应用程序中创建函数。

您需要准备一个包,除了添加dll外,还将函数.json添加到构建输出中。

我没有尝试,这并不简单,但似乎可行。

以下链接可能会对您有所帮助:

  • https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library?tabs=v2%2Ccmd#autogenerated-函数json
  • https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference#function-代码

最新更新