Home > Software design >  System.InvalidOperationException: Unable to resolve service for type 'ChatBotDashboard.Applicat
System.InvalidOperationException: Unable to resolve service for type 'ChatBotDashboard.Applicat

Time:09-27

Error: System invalid operation exception: unable to resolve service for type Chat Bot Dashboard Application Db Context while attempting to activate Chatbot API Test Controller

I am coding a WHATSAPP Chat Bot using ASP Net Core C# on Visual Studio. I have two projects in the solution. I am getting the error message on Postman when I run the project and send this basic Post Request to the API.

From what I understand, the Web App Db Context isn't able to resolve a service type while activating the API Controller in the second Project. NB: Dependency Injection is used in this API Controller.

How do I overcome this Error on Postman?

Postman API Request ErrorTest ControllerStartup ClassProgram FileProgram File

CodePudding user response:

Both projects probably are individually runnable, and therefore have their own dependency injection container. So they both register the services (e.g. like services.Add...) they need to use in their own Program.cs or Startup.cs files, which then only are accessible in the corresponding project, instead of both projects.

This is why you would need to register the database context (ensure to view it for the ASP.NET Core version that you use) in the second ASP.NET Core project as well.

  • Related