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

When IModalService is injected to a custom HttpMessageHandler in HttpClientFactory, The modal does not show. #506

Open
Huciko opened this issue Mar 8, 2023 · 1 comment
Labels
Bug Something isn't working Needs: More Information The author needs to provide more information on the issue.

Comments

@Huciko
Copy link

Huciko commented Mar 8, 2023

When IModalService is injected to a custom HttpMessageHandler in HttpClientFactory, The modal does not show.

To Reproduce

services.AddHttpClient("client", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler(sp => new ErrorHandlingMessageHandler(sp.GetRequiredService<IModalService>()));

// Custom handler code

public class ErrorHandlingMessageHandler : DelegatingHandler
{
    private readonly IModalService _modalService;

    public ErrorHandlingMessageHandler(IModalService modalService)
    {
        _modalService = modalService;
    }
 
  protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
            var response = await base.SendAsync(request, cancellationToken);
            if (!response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync(cancellationToken);
                var parameters = new ModalParameters().Add(nameof(DisplayMessage.Message), exceptionResponse.Message);
                _modalService.Show<DisplayMessage>(exceptionResponse.Title, parameters);
            }
            return response;
    }
}

Expected behavior
Modal to show

@Huciko Huciko added Bug Something isn't working Triage Issue needs to be triaged labels Mar 8, 2023
@Huciko Huciko changed the title [Bug] When IModalService is injected to a custom HttpMessageHandler in HttpClientFactory, The modal does not show. Mar 8, 2023
@chrissainty
Copy link
Member

Can you produce a repro project demonstrating this behaviour. This is the first time I've seen anyone try anything like this.

@chrissainty chrissainty added Needs: More Information The author needs to provide more information on the issue. and removed Triage Issue needs to be triaged labels Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Needs: More Information The author needs to provide more information on the issue.
Projects
None yet
Development

No branches or pull requests

2 participants