简体   繁体   中英

System.InvalidOperationException: Unable to resolve service for type 'ChatBotDashboard.ApplicationDbContext' while attempting to activate Controller

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 Error Test Controller Startup Class Program File Program File

Both projects probably are individually runnable, and therefore have their own dependency injection container . So they both register the services (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM