Support Azure Functions %value% binding expressions in trigger attributes#80
Merged
danielmarbach merged 3 commits intomainfrom Apr 28, 2026
Merged
Support Azure Functions %value% binding expressions in trigger attributes#80danielmarbach merged 3 commits intomainfrom
%value% binding expressions in trigger attributes#80danielmarbach merged 3 commits intomainfrom
Conversation
…inding expressions and update APIs to use it
…ngs and update documentation with configuration details for local testing
danielmarbach
commented
Apr 28, 2026
%value% binding expressions in trigger attributes
DavidBoike
approved these changes
Apr 28, 2026
Comment on lines
+8
to
+11
| public static class FunctionBindingExpression | ||
| { | ||
| public static string Resolve(string value, Microsoft.Extensions.Configuration.IConfiguration configuration) { } | ||
| } |
Member
There was a problem hiding this comment.
Was going to ask if this needed to be public, but then I saw the usage in the ASB-specific component, so nevermind.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The NServiceBus.AzureFunctions source generator extracts literal strings from
[ServiceBusTrigger]attributes at compile time, for example,"%billingPrefix%-api", and stores them as-is inFunctionManifest. At runtime,OverrideLocalAddress("%billingPrefix%-api")andtransport.ConnectionName = "%MyConnection%"are called with unresolved%value%patterns, which breaks the endpoint.How
%value%works in Azure FunctionsThe
%SettingName%syntax is an Azure Functions Host convention. The Host resolves these patterns against app settings before data reaches the worker process. Extensions with[SupportsDeferredBinding]receive already-resolved values viaModelBindingData.Content. The attribute instance on the worker method (via reflection) still contains raw%value%strings, but those extensions never read from it.NServiceBus.AzureFunctions doesn't use
SupportsDeferredBindingfor its trigger configuration. It needs the queue name and connection setting at startup time to configure the NServiceBus transport before any messages are received. So it can't rely on the Host's runtime resolution.Chosen approach: Resolve
%value%fromIConfigurationat startupThe isolated worker runs in the same process as the Host.
FunctionsApplicationBuilder.Configuration(IConfiguration) contains all the same settings the Host has environment variables, Key Vault references, App Configuration providers, etc. There should be no mismatch scenario.FunctionBindingExpression.Resolve(value, configuration)uses[GeneratedRegex("%([^%]+)%")]to find all%...%tokens and resolves each againstIConfiguration. It supports:%myQueue%→orders-queue%billingPrefix%-api→billing-api%prefix%-%env%-%name%→myapp-prod-orders%ServiceBus:QueueName%and%ServiceBus__QueueName%Resolution is applied in two places:
FunctionEndpointConfigurationBuilder: resolvesfunctionManifest.Addressbefore callingOverrideLocalAddressAddNServiceBusAzureServiceBusFunction: resolvesfunctionManifest.ConnectionSettingNamebefore settingtransport.ConnectionNameWhy not deferred/late resolution?
Deferred endpoint start (resolve queue name on first invocation from
BindingDataor trigger metadata) was considered but rejected because:AddNServiceBusAzureServiceBusFunction). Restructuring this to be lazy would be architecturally invasive: the entire transport, messaging pipeline, and receive infrastructure is initialized eagerly, which is something we did in the previous function package and we don't necessarily want to go back to this unless really required.IConfigurationis available at startup and contains all the same values the Host would resolve, making early resolution equivalent and simpler.Why not "just don't support it"?
Limits configurability for a pattern that Azure Functions users commonly expect. Users who want different queue names per environment (dev/staging/prod) shouldn't need different compiled binaries;
%value%seems to be the idiomatic way.