blazor-state
blazor-state copied to clipboard
Mixed enviroment with plugins who use MediatR
First I would like to thank you for your work. Blazor-State is working like a charm and makes state management super easy.
Now we have created a blazor application and integrated Blazor-State. This application is also using some custom created plugins from our company which are using MediatR for communication.
As an example it´s using a command like this:
public record UpdateSubProjectListCommand(IEnumerable<SubProjectDto> SubProjects) : IRequest;
and a handler:
public class UpdateSubProjectListCommandHandler(IInboxRegistrationDao dao, IMapper mapper) : IRequestHandler<UpdateSubProjectListCommand>
{
public async Task Handle(UpdateSubProjectListCommand request, CancellationToken cancellationToken)
{
...
}
}
Handler is called and communication with the own plugin is working. But I get a bunch of errors like this:
Exception thrown: 'System.TypeLoadException' in System.Private.CoreLib.dll ("GenericArguments[0],
'InboxRegistration.Commands.UpdateSubProjectListCommand',
on 'BlazorState.Pipeline.State.CloneStateBehavior2[TRequest,TResponse]' violates the constraint of type parameter 'TRequest'.") Exception thrown: 'System.TypeLoadException' in System.Private.CoreLib.dll ("GenericArguments[0], 'InboxRegistration.Commands.UpdateSubProjectListCommand', on 'BlazorState.Pipeline.State.CloneStateBehavior
2[TRequest,TResponse]'
violates the constraint of type parameter 'TRequest'.")
Then I tried to deactivate the UseCloneStateBehavior to false, but still exceptions are thrown. Can you please give me an advice what I can do? How can I prevent the Blazor-State clone behaviour for the other MediatR Handler which don´t implement the IAction interface?
Thanks and regards, Peter
hmm Are you on the latest version?
internal sealed class CloneStateBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : notnull, IAction
this should only run if the Request implements IAction
Yes, I´m using version 10.0 of Blazor-State
public record UpdateSubProjectListCommand(IEnumerable<SubProjectDto> SubProjects) : IRequest;
this clearly isn't implementing IAction
so why is that exception happening, is strange.
Here is chatgpt converstaion https://chat.openai.com/c/11b293f5-087e-4eeb-8b8f-425384a64c48
also there is the mediatr issue https://github.com/jbogard/MediatR/issues/823
I don't see why you are getting this just yet.
Hi Steven, thanks for your help. I can´t open your conversation with chatgpt. Also I don´t understand the behaviour. The other queries or commands don´t implement IAction at all. If this is a known bug of MediatR, then maybe it would be good to make a double check if something is really implementing IAction and just continue with the pipeline ...