Configure the project

It uses an Azure CosmosDB database to store the example application data. There is a corresponding environment variable that needs to be set to interact with CosmosDB.


Using the Cosmos DB Emulator to run the database locally

For running on local environments, Cosmos DB emulator can be used in a Windows environment.

  1. Install Cosmos DB Emulator

  2. Identify the Primary key

CosmosDB


Not using the Cosmos DB Emulator
When choosing not to run the CosmosDB locally, further configuration needs to be changed.

Set the CosmosDB URI parameter DatabaseAccountUri

<PROJECT-NAME>/src/api/xxAMIDOxx.xxSTACKSxx.API/appsettings.json
"CosmosDb": {
"DatabaseAccountUri": "<Add CosmosDB Account URI here>",
...
}

Create the Cosmos DB structure

Based on the solution template the Cosmos DB has to contain a fixed structure.

Create a collection Stacks with a container id menu (name of domain object) and the partition key /id.

CosmosDB


For the project just created to connect to the Cosmos Db database, the primary key has to be provided as a environment variable. To add this variable perform one of the next two steps.

Setting the key as a system property
  1. Replace the Cosmos DB Primary key in the command.

  2. Run the command in powershell with administrator privileges.

Run command to add the COSMOSDB_KEY system variable
[Environment]::SetEnvironmentVariable("COSMOSDB_KEY", "Cosmos DB Primary key", [EnvironmentVariableTarget]::Machine)

Set the variable specific to Visual Studio
  1. Open the project in Visual Studio. The solution file is located at src/api/xxAMIDOxx.xxSTACKSxx.API.sln.

  2. Add COSMOSDB_KEY environment variable to the launchSettings.json file generated by Visual Studio and add the Cosmos DB Primary key value.

src/api/xxAMIDOxx.xxSTACKSxx.API/properties/launchSettings.json
{
...
"profiles": {
"xxAMIDOxx.xxSTACKSxx.API": {
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"COSMOSDB_KEY": "<Add Cosmos DB Primary Key here>"
...
}
}
}
}
info

The variable is referenced in appsettings.json.

src/api/xxAMIDOxx.xxSTACKSxx.API/appsettings.json
"CosmosDb": {
...
"SecurityKeySecret": {
"Identifier": "COSMOSDB_KEY",
...
}
}