I've been trying to connect my web API project to my cosmosDB instance using keyvault, but for the life of me I can't figure out how visual studio's "connected services" are supposed to be used. I figured you would just use the variables you define in the setup process, but that doesn't seem to work- my connection string and my vault connection and I wouldn't think that you would then have to do the same definitions in the appsettings.json file, because then what would the point of the connected services tab be?
If anyone could explain to me how these work, I would greatly appreciate it. Microsoft's docs seem to only explain how to create the connection, but not quite how to use the connection afterwards.
I've tried looking through microsoft's docs and multiple web tutorials, but I can't seem to make sense of it on my own.
Connected services can be any Azure Services like
Azure KeyVault,Cosmos DB.Follow the below steps to
Add Connected Service.Web APIbefore addingservice dependenciesto theConnected Services.Right click on the
Projectfolder =>Add=>Connected Service=> click onAdd a service dependency=> select the required Service -Azure Key Vault/Azure Cosmos DB.Program.cs.Added Azure Cosmos DB
ConnectionStringin the already addedKeyVault.After adding
service dependenciesThe below packages are added in the
.csprojfileserviceDependencies.jsonwill be created withdependencies.By using Connected Services, few configurations like adding NuGet Packages, settings in
launchSettings.jsonare configured by default.In
launchSettings.json, below settings are added automatically.KeyVault/DBsettings inappsettings.jsonand on top you have added Connected Services, then the values fromappsettings.jsonwill be replaced with the values fromConnected Servicesat run time.References taken from Visual Studio Connected Services and MSDoc