Skip to content

Send-only endpoint attribute with declarative connection configuration#113

Open
andreasohlund wants to merge 24 commits into
mainfrom
send-only-endpoints
Open

Send-only endpoint attribute with declarative connection configuration#113
andreasohlund wants to merge 24 commits into
mainfrom
send-only-endpoints

Conversation

@andreasohlund
Copy link
Copy Markdown
Member

@andreasohlund andreasohlund commented Jun 3, 2026

Replaces startup-registered send-only endpoints with attribute-driven generation and adds declarative connection configuration for both trigger and send-only endpoints.

What changed

  • Added [NServiceBusSendOnlyFunction] attribute with optional Connection property to specify the configuration key used to resolve the transport connection
  • Added IConnectionSettingManifest interface shared by FunctionManifest and SendOnlyEndpointManifest, providing a uniform ConnectionSettingName property
  • Made AzureServiceBusServerlessTransport.ConnectionName internal so that connection configuration only flows through the attribute and source generator pipeline
  • Added dedicated SendOnlyEndpointGenerator that discovers and generates registration code for send-only endpoints
  • Removed AddSendOnlyNServiceBusEndpoint(...) in favor of generated registrations
  • Updated composition generation so builder.AddNServiceBusFunctions() registers both function endpoints and send-only endpoints
  • Updated integration app to use [NServiceBusSendOnlyFunction("client", Connection = "AzureWebJobsServiceBus")]

Send-only endpoint model

A send-only endpoint is defined with the [NServiceBusSendOnlyFunction] attribute on a static configuration method:

[NServiceBusSendOnlyFunction("client", Connection = "MyCustomConnection")]
public static void ConfigureClient(
    EndpointConfiguration endpointConfiguration,
    IServiceCollection services)
{
}

The Connection property holds the name of the configuration key (not the connection string value itself). When omitted, the transport uses its default connection name.

Supported method shape:

  • must be static
  • first parameter must be EndpointConfiguration
  • optional additional parameters: IServiceCollection, IConfiguration, IHostEnvironment
  • method name must match Configure{EndpointName} (case-insensitive)

Connection configuration flow

Both trigger-based and send-only endpoints now follow the same path for connection resolution:

Trigger-based: The Connection property on the trigger attribute (e.g. [ServiceBusTrigger(Connection = "...")]) is extracted by the source generator, flows through FunctionManifest.ConnectionSettingName, and is applied to the transport by the registration method.

Send-only: The Connection property on [NServiceBusSendOnlyFunction] is extracted by the source generator, flows through SendOnlyEndpointManifest.ConnectionSettingName, and is applied to the transport by the registration method.

Both manifests implement IConnectionSettingManifest, so the registration method uses a single helper to apply the connection setting name to the transport.

@andreasohlund
Copy link
Copy Markdown
Member Author

@danielmarbach the source generation was not separated as expected, fixing that now

@andreasohlund andreasohlund marked this pull request as ready for review June 3, 2026 08:58

using Microsoft.Extensions.DependencyInjection;

file static class UsesGlobalTypes
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing this

@andreasohlund andreasohlund requested a review from DavidBoike June 3, 2026 11:58
@danielmarbach danielmarbach changed the title Support send-only endpoints via a [NServiceBusSendOnlyEndpoint] attribute Send-only endpoint attribute with declarative connection configuration Jun 3, 2026
Comment on lines +105 to +106
title: "Invalid NServiceBus send-only endpoint method",
messageFormat: "Method '{0}' is not a valid NServiceBus send-only endpoint: {1}",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavidBoike this needs some editorial love

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants