如何添加Azure Functions扩展 [英] How to add Azure Functions extension

查看:73
本文介绍了如何添加Azure Functions扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Azure扩展中进行尝试,如此问题但无法正常工作.

I'm experimenting with extensions in Azure Functions as shown in this question but can't get it to work.

我的代码如下:(预编译的消费计划)

My code looks like this: (pre-compiled, consumption plan)

public static class FirstFunction
{
    [FunctionName("FirstFunction"),]
    public static void Run([TimerTrigger("0 */5 * * * *", RunOnStartup = true)]TimerInfo myTimer, TraceWriter log)
    {
        log.Info($"Started = { TestExtension.Started }");
        log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
    }
}

public class TestExtension : IExtensionConfigProvider
{
    public static bool Started = false;

    public void Initialize(ExtensionConfigContext context) {
        Started = true;
        Console.WriteLine("TestExtensionConsole");
        context.Trace.Error("TestExtension");

        throw new Exception("TextExtensionException");
    }
}

但是在运行时什么也没有发生.我看到了计时器Started = false的日志,但没有其他内容.

But nothing happens at runtime. I see the log from the timer Started = false but nothing else.

我需要启用扩展功能吗?

Do I need to enable extensions or something?

推荐答案

启动时运行代码并非完全是IExtensionConfigProvider的目的.它被设计为用户创建自定义绑定的可扩展点.

Running code on startup is not exactly the purpose of IExtensionConfigProvider. It's designed as extensibility point for user to create custom bindings.

因此,除非您的函数使用自定义绑定,否则运行时主机不会自动加载IExtensionConfigProvider的实现,请参见

So, unless your functions are using custom bindings, the implementations of IExtensionConfigProvider won't be auto-loaded by the runtime host, see code.

您所指的答案的作者正在使用他的扩展名实现依赖注入具有自定义绑定,因此适用于他.

The author of the answer that you are referring to was using his extension to implement Dependency Injection with custom bindings, so it works for him.

如果您打算将扩展名用于自定义绑定,请在函数中使用该绑定,然后该扩展名将开始加载.

If you intend to use your extension for custom binding, then use that binding in a function and the extension will start loading.

这篇关于如何添加Azure Functions扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆