Azure / Azure/azure-functions-dotnet-worker

Isolated process - Definite documentation on how to write custom binding and triggers, and troubleshoot section

Open
#2,092 26 comments 17 reactions 1 assignee Claimed by @RohitRanjanMS View on GitHub
area: binding area: documentation
Dominant language
C#
Stars
466
Forks
215
Avg merge
3d 10h
Merged PRs (30d)
7

Description

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:
```csharp
// 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 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:

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

}

// In MyFunction class

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

Using an "input" binding instead brings an error:

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

}

// In MyFunction class

[Function("Try_Get")]
public async Task 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.