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");
}
}
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?
Running code on startup is not exactly the purpose of IExtensionConfigProvider
. It's designed as extensibility point for user to create custom bindings.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With