Closed sc-cpais closed 2 years ago
Hi @sc-cpais , I have the same issue. Did you find a way to resolve it? Thanks in advance
Same issue here!
Hi @sylvainonweb @mohammedbabelly
I end up finding the solution and forgot to update the issue. Thank you for commenting. In Hot chocolate, we receive the injected service by method parameter. Something like this:
public async Task<ProjectEnergyDto> AddProjectEnergy([Service]ISender mediator, CreateEnergyProjectCommand model) { return await mediator.Send(model); }
Hope that can help you.
Hi @sylvainonweb @mohammedbabelly
I end up finding the solution and forgot to update the issue. Thank you for commenting. In Hot chocolate, we receive the injected service by method parameter. Something like this:
public async Task<ProjectEnergyDto> AddProjectEnergy([Service]ISender mediator, CreateEnergyProjectCommand model) { return await mediator.Send(model); }
Hope that can help you.
Thank you so much, sir.
Hi everyone,
we are building a project with GraphQL (hot chocolate) + Mediator. The queries on graphql are served by the service layer directly and the mutations are service my mediator:
[GraphQLDescription("Represents the queries available.")] public class Query { public IList<ProjectsListDto> GetProjects([Service] IProjectQueryService projectService) { return projectService.GetProjects(default, default); } }
` public class Mutation { private readonly IMediator mediator;
This is my UpdateEnergyProjectCommand
public class UpdateEnergyProjectCommand : IRequestant this is my UpdateEnergyProjectHandler
` public class UpdateEnergyProjectHandler : IRequestHandler<UpdateEnergyProjectCommand, ProjectEnergyDto> { private readonly IProjectQueryService projectQueryService; private readonly IEnergyProjectRepository energyProjectRepository; private readonly IMapper mapper;
warning manage not found exception
`
When I run the code, everything runs well. But when I run it right after I get the following exception: Cannot access a disposed object.\r\nObject name: 'IServiceProvider'.
I have tried this solution but it didn't worked for me.
"extensions": { "message": "Cannot access a disposed object.\r\nObject name: 'IServiceProvider'.", "stackTrace": " at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()\r\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)\r\n at MediatR.ServiceFactoryExtensions.GetInstances[T](ServiceFactory factory)\r\n at MediatR.Internal.RequestHandlerWrapperImpl
2.Handle(IRequest1 request, CancellationToken cancellationToken, ServiceFactory serviceFactory)\r\n at MediatR.Mediator.Send[TResponse](IRequest
1 request, CancellationToken cancellationToken)\r\n at SC.Certification.API.GraphQL.Mutation.UpdateProjectEnergy(UpdateEnergyProjectCommand model) in C:\sources\SC.Certification\SC.Certification.API\GraphQL\Mutation.cs:line 25\r\n at HotChocolate.Resolvers.Expressions.ExpressionHelper.AwaitTaskHelper[T](Task1 task)\r\n at HotChocolate.Types.FieldMiddlewareCompiler.<>c__DisplayClass3_0.<<CreateResolverMiddleware>b__0>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n at HotChocolate.Execution.Processing.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\n at HotChocolate.Execution.Processing.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)" }
Can somebody help here? Thank you