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,199 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,449 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.
301 questions
{count} votes