如何添加 Azure Functions 扩展
How to add Azure Functions extension
我正在试验 Azure Functions 中的扩展,如 所示,但无法正常工作。
我的代码是这样的:(预编译,消费计划)
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
看到了日志,但没有别的。
我需要启用扩展程序还是什么?
运行 启动时的代码不完全是 IExtensionConfigProvider
的目的。它被设计为用户创建自定义绑定的扩展点。
因此,除非您的函数使用自定义绑定,否则运行时主机不会自动加载 IExtensionConfigProvider
的实现,请参阅 code。
您所指的答案的作者使用了他对 implement Dependency Injection 的扩展和自定义绑定,因此它适用于他。
如果您打算将扩展用于自定义绑定,请在函数中使用该绑定,扩展将开始加载。
我正在试验 Azure Functions 中的扩展,如
我的代码是这样的:(预编译,消费计划)
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
看到了日志,但没有别的。
我需要启用扩展程序还是什么?
运行 启动时的代码不完全是 IExtensionConfigProvider
的目的。它被设计为用户创建自定义绑定的扩展点。
因此,除非您的函数使用自定义绑定,否则运行时主机不会自动加载 IExtensionConfigProvider
的实现,请参阅 code。
您所指的答案的作者使用了他对 implement Dependency Injection 的扩展和自定义绑定,因此它适用于他。
如果您打算将扩展用于自定义绑定,请在函数中使用该绑定,扩展将开始加载。