Pure.Krome Pure.Krome - 1 month ago 8
C# Question

How does the Azure WebJobs SDK allow a specific list of parameters to be injected into a Function method?

The Azure SDK (for Queues) mentions a specific list of parameters that are allowed to be passed into a webjob Function.

e.g.


You can get the following message properties by adding parameters to
the method signature:

DateTimeOffset expirationTime


DateTimeOffset insertionTime


DateTimeOffset nextVisibleTime


string queueTrigger
(contains message text)

string id


string popReceipt


int dequeueCount


If you want to work directly with the Azure storage API, you can also add a
CloudStorageAccount
parameter.


I'm trying to find how this is done in their source code because I want to try playing around with passing my own parameters in.

Can anyone please explain / link how this is possible / done?

Answer

Such parameters are part of the static binding contract for a particular trigger binding. Each trigger binding defines its (possibly empty) set of "built in" binding values. E.g. here is the source code for QueueTrigger where it defines these values. Only values in this static contract can be bound as method parameters in this way.

The runtime verifies method signatures against the contract for the trigger at index time which is why I refer to this as a static contract. If one or more parameters of the method cannot be resolved against the contract, an indexing error occurs. At runtime when a method is triggered, the binding contract is populated with values from the actual trigger value (e.g. the queue message).

Extension trigger bindings can define contracts in the same way. For example, here is where the HttpTrigger binding in Azure Functions adds route parameters from a route template to its binding contract. E.g. for a route template like products/{category:alpha}/{id:int?} both "category" and "id" are added to the contract, and can therefore be bound to directly as method parameters. At runtime the binding data is populated with the actual runtime values from the triggering http request URL.

The definition of this contract is the responsibility of the trigger binding author, and it is not extensible from the outside.