在隔离进程 Azure 函数中将 C# HostBuilder 管道转换为 F#

Convert C# HostBuilder pipeline to F# in isolated process Azure function

以下代码来自https://docs.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide

using Microsoft.Extensions.DependencyInjection;

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(s =>
    {
        s.AddSingleton<IHttpResponderService, DefaultHttpResponderService>();
    })
    .Build();
  
await host.RunAsync();

F# 的等价物是什么?

就将 C# 转换为 F# 而言,代码如下所示:

open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Microsoft.Azure.Functions.Worker.Configuration

let host =
    HostBuilder()
        .ConfigureFunctionsWorkerDefaults()
        .ConfigureServices(fun s ->
            s.AddSingleton<IHttpResponderService, DefaultHttpResponderService>()
        )
        .Build()

task {
    do! host.RunAsync()
} |> ignore

我不熟悉 Azure Functions,所以我不知道 RunAsync() 是应该被忽略还是其他。文档没有说清楚,所以我选择忽略它。