Azure-docs: CosmosClient singleton is added in Startup but not used in the Function

Created on 3 Sep 2019  Â·  6Comments  Â·  Source: MicrosoftDocs/azure-docs

In the code example, a CosmosClient singleton is added in Startup. However, the CosmosClient is not used in the Function.
How do I access the CosmosClient from the function?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri1 azure-functionsvc cxp product-question triaged

All 6 comments

Hi @mfalkvidd Thanks for reaching out. We will review and update this as appropriate.

@mfalkvidd You can inject the CosmosClient directly.

There's an example of this in the Cosmos client samples directory which includes the following code:

private CosmosClient cosmosClient;

public AzureFunctionsCosmosClient(CosmosClient cosmosClient)
{
this.cosmosClient = cosmosClient;
}

Thanks @DixitArora-MSFT
Sorry for being unclear.

I'm not actually interested in using the Cosmos client. I just expected the documentation on how to use dependency injection to actually use the dependencies that are injected.

Imho, the documentation could be made clearer by either of:
a) Remove everything that mentions Cosmos, since the cosmos service isn't used
b) Add the CosmosClient to the HttpTrigger constructor and use the cosmos client from the GetPosts function.

@mfalkvidd I have created the PR for this which will address this. Thanks so much for providing the feedback that help us in improving the documentation. For now I will proceed with closure of this and If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue.

@DixitArora-MSFT could you add a reference to the PR here (or reference this issue from the PR)?

@mfalkvidd, @DixitArora-MSFT Just a heads-up that I have a draft of this article currently in review by the Product Team that removes the Cosmos DB references as well as many other updates. Once we finish the final review the new version will go live soon after.

Was this page helpful?
0 / 5 - 0 ratings