[FEATURE REQ] Enable dependency injection for ServiceBusAdministrationClient
See original GitHub issueLibrary name
Azure.Messaging.ServiceBus
Please describe the feature.
Hi,
In Compatability/ServiceBusClientBuilderExtensions.cs
in the Azure.Messaging.ServiceBus.sln
we have a method to register a ServiceBusClient.
/// <summary>
/// Registers a <see cref="ServiceBusClient"/> instance with the provided <paramref name="fullyQualifiedNamespace"/>.
/// </summary>
///
public static IAzureClientBuilder<ServiceBusClient, ServiceBusClientOptions> AddServiceBusClientWithNamespace<TBuilder>(this TBuilder builder, string fullyQualifiedNamespace)
where TBuilder : IAzureClientFactoryBuilderWithCredential
{
return builder.RegisterClientFactory<ServiceBusClient, ServiceBusClientOptions>((options, token) => new ServiceBusClient(fullyQualifiedNamespace, token, options));
}
Which allows registering it for DI via the following method
public static IServiceCollection AddServiceBusUtil(this IServiceCollection services, IConfiguration config)
{
_ = config ?? throw new ArgumentNullException(nameof(config));
services.AddAzureClients(builder => {
builder.AddServiceBusClientWithNamespace(config.GetConnectionString("ServiceBus"));
});
return services;
}
Which is great and makes managing client / client lifetime a lot easier.
Perhaps I missed another extension method, but it appears that there is no equivalent for it for the ServiceBusAdministrationClient
It appears that using ServiceBusAdministrationClient ServiceBusAdministrationClientOptions would yield the same result. Is there more to it than adding a new extension method like this?
I’ve tested it out in my own application and it appears doing the same trick would be enough.
services.AddAzureClients(builder => {
builder.AddServiceBusClientWithNamespace(config.GetConnectionString("ServiceBus"));
(builder as IAzureClientFactoryBuilderWithCredential).RegisterClientFactory<ServiceBusAdministrationClient, ServiceBusAdministrationClientOptions>((options, token) => new ServiceBusAdministrationClient(config.GetConnectionString("ServiceBus"), token, options));
});
If it is a case of creating the same set of operations ServiceBusAdministrationClient offers I am more than happy to create a PR to support that.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:5 (5 by maintainers)
Top GitHub Comments
Thanks for the help resolving this @JoshLove-msft
Thank you for your feedback. Tagging and routing to the team member best able to assist.