Koen
Koen

Reputation: 17

How do I get the connectionstring of a ServiceBusClient?

using Azure.Messaging.ServiceBus;

I currently have a ServiceBusClient where I pass the connectionString as a parameter to its constructor:

var client = new ServiceBusClient(connectionString);

Now imagine I have another class called Handler which expect a ServiceBusClient as a parameter to its constructor:

var handler = new Handler(client);

Now inside the constructor of Handler, is there any way where I can get the exact connectionString which client got as a parameter to its constructor?

public Handler(ServiceBusClient client)
{
    var connectionStringOfClient = ...?
}

Haven't found a simple property yet offering said connectionString, so I'm wondering if there is any other way.

Thank you!

Upvotes: 0

Views: 556

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136226

Simple answer is that you can't. Only property that you can get out of the ServiceBusClient is FullyQualifiedNamespace.

The reason you can't get the connection string information from the client is because there are many ways by which you can create an instance of ServiceBusClient and using connection string is just one of them. For all the possible constructor overloads, please see here.

Upvotes: 2

Related Questions