Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixed enviroment with plugins who use MediatR #372

Open
phomberger opened this issue Jan 29, 2024 · 4 comments
Open

Mixed enviroment with plugins who use MediatR #372

phomberger opened this issue Jan 29, 2024 · 4 comments

Comments

@phomberger
Copy link

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.CloneStateBehavior2[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

@StevenTCramer
Copy link
Collaborator

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

@phomberger
Copy link
Author

Yes, I´m using version 10.0 of Blazor-State

@StevenTCramer
Copy link
Collaborator

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 jbogard/MediatR#823

I don't see why you are getting this just yet.

@phomberger
Copy link
Author

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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants