C
C#10mo ago
CoreVisional

Difference in using the second overloaded method and first method from CosmosClient

Hi, I am trying to understand what's the difference in using the second overloaded method in CosmosClient compared to just supply the connection string using the first overloaded method of CosmosClient? I understand that the second requires me to provide the endpoint uri and primary key, but why is there a need for the second overloaded method if CosmosClient(string connectionString, CosmosClientOptions clientOptions = null) already simplifies my work. Is there a reason(s) that I should be using the second one? Note that I am using the latest Azure CosmosDB SDK v3 for my ASP.NET Core 7 application.
5 Replies
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
CoreVisional
CoreVisionalOP10mo ago
Sorry, forgot to provide the code section I was referring to: From CosmosClient.cs:
public CosmosClient(string connectionString, CosmosClientOptions clientOptions = null)
: this(CosmosClientOptions.GetAccountEndpoint(connectionString), CosmosClientOptions.GetAccountKey(connectionString), clientOptions)
{
}

public CosmosClient(string accountEndpoint, string authKeyOrResourceToken, CosmosClientOptions clientOptions = null)
{
if (string.IsNullOrEmpty(accountEndpoint))
{
throw new ArgumentNullException("accountEndpoint");
}

if (string.IsNullOrEmpty(authKeyOrResourceToken))
{
throw new ArgumentNullException("authKeyOrResourceToken");
}

Endpoint = new Uri(accountEndpoint);
AccountKey = authKeyOrResourceToken;
ClientContext = ClientContextCore.Create(this, clientOptions);
}
public CosmosClient(string connectionString, CosmosClientOptions clientOptions = null)
: this(CosmosClientOptions.GetAccountEndpoint(connectionString), CosmosClientOptions.GetAccountKey(connectionString), clientOptions)
{
}

public CosmosClient(string accountEndpoint, string authKeyOrResourceToken, CosmosClientOptions clientOptions = null)
{
if (string.IsNullOrEmpty(accountEndpoint))
{
throw new ArgumentNullException("accountEndpoint");
}

if (string.IsNullOrEmpty(authKeyOrResourceToken))
{
throw new ArgumentNullException("authKeyOrResourceToken");
}

Endpoint = new Uri(accountEndpoint);
AccountKey = authKeyOrResourceToken;
ClientContext = ClientContextCore.Create(this, clientOptions);
}
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
CoreVisional
CoreVisionalOP10mo ago
Yeah I take it that that is for the primary key. But, I can also just connect using the first method by providing the connection string, which works just as fine for me, so I don't get the point of the second overloaded method, unless it is for explicitness and flexibility?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server