azure-functions-dotnet-worker: Isolated process - Definite documentation on how to write custom binding and triggers, and troubleshoot section

Hello, I have a hard time making anything work in the isolated worker model. All the available doc is about the in-process model, which is ironic since Microsoft is pushing us towards the other one.

Where can I find a definitive documentation on how to write custom bindings and triggers for the isolated worker?

For example, I just want to be able to inject a class into my functions. But the only place it works is on the class constructor, while I want one per-function call.

Pseudo code:

// Types to inject
public interface IMyType {}
public class MyType : IMyType {}

// Register them
[assembly: WorkerExtensionStartup(typeof(MyExtensionStartup))]
public sealed class MyExtensionStartup : WorkerExtensionStartup
{
    public override void Configure(IFunctionsWorkerApplicationBuilder applicationBuilder)
    {
        applicationBuilder.Services.AddSingleton(typeof(IMyType), typeof(MyType));
    }
}

// Function
public class MyFunction
{
    private readonly IMyType _my;
    public MyFunction(IMyType> my)
    {
        _my = my; // OK
    }
    
    [Function("Try_Get")]
    public async Task<HttpResponseData> Get(
        [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequestData request,
        CancellationToken token,
        IMyType? my = null
    )
    {
        // my is always null
        return request.CreateResponse(HttpStatusCode.OK);
    }
}

I also tried using an attribute but I don’t know how to make it work and there is no documentation for that:

[AttributeUsage(AttributeTargets.Parameter)]
public class MyBindingAttribute : BindingAttribute
{

}

// In MyFunction class

    [Function("Try_Get")]
    public async Task<HttpResponseData> Get(
        [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequestData request,
        CancellationToken token,
        [MyBinding] IMyType? my = null
    )

Using an “input” binding instead brings an error:

[AttributeUsage(AttributeTargets.Parameter)]
public class MyBindingInputAttribute : InputBindingAttribute
{

}

// In MyFunction class

    [Function("Try_Get")]
    public async Task<HttpResponseData> Get(
        [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequestData request,
        CancellationToken token,
        [MyBindingInput] IMyType? my = null
    )

The ‘Try_Get’ function is in error: The binding type(s) ‘myBinding’ are not registered. Please ensure the type is correct and the binding extension is installed.

Would be nice to have a documentation page to troubleshoot those errors. It is pointless to report them if there is no way to find a solution.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 13
  • Comments: 25 (3 by maintainers)

Most upvoted comments

This is a serious problem… We use custom INPUT bindings to parse auth tokens/Claims. To convert to net8 / isolated, these need to work, and there is NO documentation, or even mention of a breaking change.

Adding my .02: this is maddening and sadly becoming par for the course with Microsoft SDKs. I used INameResolver from WebJobs in my in-proc function to enable this for dynamic queue names. These are mandatory to assign the correct queues when deploying in the SDLC ("dev-queue1’, “int-queue1”, etc.). There is nothing comparable in isolated mode.

I seriously question whether any of these library devs deal with real-world scenarios or if they’re just regurgitating what they learned in some sophomore CS coding class, from a professor also lacking real-world experience.

I am having the same problem here.

Our company uses in-proc input and output bindings that we want to migrate to the isolated worker, but the documentation we found so far is not enough, especially to help understand how to create and use custom output bindings.

Hello, same problem here. We have many custom bindings that we need to migrate to Workers.

For example we implemented Coap, Mqtt, Mongo, OpcUa, Redis, IotHub (fe: registry input, ack trigger and cloud to device messages).

By reading some articles and looking at your workers implementation (EventHub, ServiceBus, Blob etc) I understood that in every new project I have to:

  • create new Attributes to “pass” configuration settings
  • create an implementation of IInputConverter for each trigger or input bindings
  • create an implementation of IOutputConverter for each output binding
  • add [assembly: ExtensionInformation(“<My.CustomBinding.Extension>”, “X.X.X”)] to refer to my custom, binding

So my questions are:

  • Are my assumptions correct?
  • Are the IInputConverters and IOutputConverters the classes to allow rich bindings? Or what is the pourpose of these interfaces?
  • How can i control the way the binding object is passed from host to isolated process?
  • The most complete example i found is the blob trigger, when you are going to provide documentation about how to implement a custom binding?
  • For example in the Coap binding for the in-process function I bind the “Request” and after that I write the response by using that object, what is the strategy or what changes do I have to make to to my custom binding to support this feature in isolated process too?

Hello,

Any update on this issue? Is there any document to implement Custom attribute trigger?

Currently encountering the same black hole regarding documentation on custom trigger bindings in the world of isolated worker functions.

It’s currently blocking us from migrating to the isolated worker model.

Other than a couple of articles and trying to reverse engineer the existing worker extensions for OOTB triggers/input/output bindings, there really isn’t anything out there.

If custom triggers is something the Azure functions team don’t intend to support going forward (as alluded to in an earlier comment), then that should be stated explicitly.

yeah, I was referring to that doc, let me follow-up with the team.

What is “here”? I don’t see a link.

And we still can’t make a custom trigger work (like the sample project I shared more than a year ago). And no documentation on how to write one exists (or it is hard to find if there is any).

https://github.com/Azure/azure-functions-dotnet-worker/issues/2092#issuecomment-1849599571

Any update on this? I am also finding that having attributes in conjunction with middleware would make my code much cleaner rather than having to implement an ugly if-else inside my middleware for such functionality.

For example… the following does NOT work in isolated worker processes but used to with the in-process model…

TestFunctions.cs

[AuthorizationAtribute([Permissions.Admin])]
[Function("test1")]
public Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "test1")] HttpRequestData req){}

[AuthorizationAtribute([Permissions.IndividualUser])]
[Function("test2")]
public Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "test2")] HttpRequestData req){}

AuthorizationAttribute.cs

[AttributeUsage(AttributeTargets.All)]
public class AuthorizationAttribute(string[] requiredPermissions) : Attribute
{
  // Check user permissions against function required permissions
  public Task<bool> CheckPermissions(){}
}

Related question on Stack Overflow on how to migrate/use Custom Binding and Authorization Attribute.

An attempt to Blog about it by @maartenba 2021 Custom bindings with Azure Functions .NET Isolated Worker was only successful for string inputs, after some hacks on the csproj file and extensions.json, with dependencies on isolated worker runtime having access to NuGet to download packages.

Isolated Worker docs, blogged on techcommunity.microsoft.com by @cloudmelon are vaguley helpful till they are not here

Hello,

Is there any update on this?

Stumbled upon this.

Any update guys?

Agreed. There seems to be no documentation at all for how to build a custom binding with the isolated worker model. The best I could find was that building on top of your example you need to build a class that implements IInputConverter and then attach it to the InputAttribute using this: [InputConverter(typeof(MyInputConverter))]

But that is also not enough to get the binding registered, I get the same error message as you:

The ‘Try_Get’ function is in error: The binding type(s) ‘myBinding’ are not registered. Please ensure the type is correct and the binding extension is installed.