【问题标题】:Where is the IoC happening in an Azure Durable Function?Azure Durable Function 中的 IoC 发生在哪里?
【发布时间】:2020-10-24 18:43:11
【问题描述】:

此代码直接来自 Visual Studio 2019 中的 Durable Function 启动

    [FunctionName("Orchestrator_HttpStart")]
    public static async Task<HttpResponseMessage> HttpStart(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
        [DurableClient] IDurableOrchestrationClient starter,
        ILogger log)
    {
        // Function input comes from the request content.
        string instanceId = await starter.StartNewAsync("Orchestrator", null);

        log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

        return starter.CreateCheckStatusResponse(req, instanceId);
    }

IDurableOrchestationClient starterILogger log 的值来自哪里?由于这些参数不会在 HTTP 请求中传递,我假设幕后一定发生了一些 IoC 魔术,但我不完全确定它是什么/在哪里。

【问题讨论】:

标签: c# azure dependency-injection azure-functions azure-durable-functions


【解决方案1】:

我假设幕后一定有一些 IoC 魔术。

正确。

IDurableOrchestrationClient 的值从何而来?

IoC 来自 AddDurableTask (source)。 IDurableClientFactory 创建继承自 IDurableOrchestrationClientIDurableClient。您可以找到AddDurableTask here 的用法示例。

serviceCollection.TryAddSingleton<IDurableClientFactory, DurableClientFactory>();

ILogger 的值从何而来?

(正如@Ian Kemp 和@Nkosi 已经指出的那样)

IoC 来自AddWebScriptHost (source)。 ILoggerFactory 创建 ILogger

loggingBuilder.Services.AddSingleton<ILoggerFactory, ScriptLoggerFactory>();

【讨论】:

    猜你喜欢
    • 2019-10-01
    • 2021-01-07
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多