System.InvalidOperationException: Unable to resolve service for type 'MovieApi_backend.database.Cont

when i connect my application to database postgresql and when i hit the post req getting error can some one help me this System.InvalidOperationException: Unable to resolve service for type 'MovieApi_backend.database.Context' while attempting to activate 'MoviesController'. at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ThrowHelperUnableToResolveService(Type type, Type requiredBy) at lambda_method9(Closure, IServiceProvider, Object[]) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>cDisplayClass6_0.<CreateControllerFactory>gCreateController|0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>gAwaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>gAwaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
No description
No description
8 Replies
ThePuppetMaster
ThePuppetMaster3mo ago
No description
Jimmacle
Jimmacle3mo ago
that startup class looks wrong, there is no request pipeline configuration show your Program.cs
ThePuppetMaster
ThePuppetMaster3mo ago
No description
Jimmacle
Jimmacle3mo ago
given that code, how do you suppose your startup class code is being called? why do you have a startup class in the first place?
ThePuppetMaster
ThePuppetMaster3mo ago
Thanks bro it working i have add the database class in the Program.cs file and one more thing how can i improve the code like remove unnecessary class or code
Jimmacle
Jimmacle3mo ago
remove the Startup class if you haven't already, besides that you haven't shown much code so i can't really tell you and learn to use the debugger instead of putting Console.WriteLine everywhere $debug
MODiX
MODiX3mo ago
Tutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
ThePuppetMaster
ThePuppetMaster3mo ago
thnaks