Visual Studio team added Azure Cosmos DB Emulator into Connected Services in the Visual Studi version 17.2. This makes life much easier for Cosmos DB developers. In this post, I will share how to configure Cosmos DB Emulator for a project in Visual Studio 2022. You can reach Connected Services from the Project menu or you can right-click on your project and select add then select the connected services to see the options.
I select the Azure Cosmos DB Emulator from the container from this list. You will see the container information and settings after that.
After you click Next, you should see the connection string for Azure Cosmos DB Emulator. You will need to give a name for the connection string. This will be the name you will use to retrieve connection string from your application. In the following example, my connection string name is localCosmos and I wanted to save the connection string in the local user secrets file.
After you click the Finish button you should see the success message and see the Azure Cosmos DB Emulator in the Service Dependencies list. If you picked the Local user secrets file, you will need to get the connection string from the secrets.json file. Don't forget to use Singleton when you declare DocumentClient with the connection string!
No comments:
Post a Comment