Web API addCustomer service faced error when connecting Azure Cosmos DB

Ying Kit Li 1 Reputation point
2021-11-14T12:54:54.387+00:00

System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Azure.Cosmos.CosmosClient' while attempting to activate 'CosmosWebAPI.Controllers.CosmosDbService'.

I got the above exceptions when running the below api service in local swagger site:

[Route("/AddCustomer")]
HttpPost]
public async Task AddAsync(Customer item) {
await _container.CreateItemAsync(item, new PartitionKey(item.Id));
}

Please help.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,573 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,643 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
338 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.