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](https://cdn.answeroverflow.com/1225184299301736488/Screenshot_from_2024-04-04_02-13-30.png)
![No description](https://cdn.answeroverflow.com/1225184299670704234/Screenshot_from_2024-04-04_02-14-23.png)
8 Replies
![No description](https://cdn.answeroverflow.com/1225184461067649105/Screenshot_from_2024-04-04_02-15-21.png)
that startup class looks wrong, there is no request pipeline configuration
show your Program.cs
![No description](https://cdn.answeroverflow.com/1225199706657783878/Screenshot_from_2024-04-04_03-15-36.png)
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?
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
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
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.
thnaks