Within my blazor app i have a webassembly app and a web api app.I have written a base for a DelegatingHandler within my webassembly to get my token from local storage and send it.I will want to send the token and if the response is a unauthorized one then ill send a refresh token.When i create my handler like this:
public class AuthHandler: System.Net.Http.DelegatingHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var response = base.SendAsync(request, cancellationToken); Console.WriteLine("This is form the handler"); return response; }}and in program.cs
builder.Services.AddTransient<AuthHandler>();builder.Services.AddHttpClient("DefaultClient", client => { client.BaseAddress = new Uri("https://localhost:7124"); }).AddHttpMessageHandler<AuthHandler>();it build and logs fine.However, if i try and inject my service like this:
public class AuthHandler(ILocalStorageService localStorageService) : System.Net.Http.DelegatingHandler{ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var response = base.SendAsync(request, cancellationToken); Console.WriteLine("This is form the handler"); return response; }I get an error of Error: One or more errors occurred. (ValueFactory attempted to access the Value property of this instance.)Does any one know how to solve this?Thanks