Skip to content

Instantly share code, notes, and snippets.

@ealsur
Created April 16, 2021 17:56
Show Gist options
  • Save ealsur/01b99715c98e11a6bd0ce7c4ea5e80dd to your computer and use it in GitHub Desktop.
Save ealsur/01b99715c98e11a6bd0ce7c4ea5e80dd to your computer and use it in GitHub Desktop.
Create and initialize CosmosClient
List<(string, string)> containers = new List<(string, string)>
{
("DatabaseNameForContainer1", "ContainerName1"),
("DatabaseNameForContainer2", "ContainerName2")
};
CosmosClientOptions cosmosClientOptions = new CosmosClientOptions
{
ApplicationName = "MyApplicationName",
// any other setting I want to customize
};
CosmosClient cosmosClient = await CosmosClient.CreateAndInitializeAsync(connectionString, containers, cosmosClientOptions);
@cannehag
Copy link

This is kind of getting to my point with the post :)
If you try that code you see that you don't have access to the serviceProvider at that stage.

I understand that my question might be tricky to solve, but at least to me, this looks like a pretty normal setup of a client.

@ealsur
Copy link
Author

ealsur commented Apr 29, 2021

I see what you mean, you cannot read the config because in your case it comes from serviceProvider.

I've seen cases from it coming from the Configuration, which is built before the services are added (so it's available there).

@cannehag
Copy link

cannehag commented May 3, 2021

Yes, I went with that option instead. That works too :)
Thanks!

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