There is no registered service of type

You should replace

@inject ServerAuthenticationStateProvider AuthenticationStateProvider

with

@inject AuthenticationStateProvider AuthenticationStateProvider

because that is how you registered it.


Note: When you add a service to the DI container, the left-side parameter should be an interface ( or an abstract class), whereas the right-side parameter should be the concrete class, like the following:

services.AddScoped<IJSRuntime, RemoteJSRuntime>();

And you can inject the type IJSRuntime into your component like this:

@inject IJSRuntime JSRuntime

IJSRuntime is the type to inject, JSRuntime is the name of the property which will contain the injected instance

Why do you call your class ServerAuthenticationStateProvider This is the very same name of the AuthenticationStateProvider added to your DI container by the Blazor framework:

ComponentServiceCollectionExtensions.AddServerSideBlazor method:

services.AddScoped<AuthenticationStateProvider, ServerAuthenticationStateProvider>();

Please, modify your app according to the comments above, run your app, and come to report of errors,if any...

Important

  • Make sure you understand the role and functionality of the AuthenticationStateProvider type, how it is populated with the authentication state data, when, and by whom. You should have derived your custom AuthenticationStateProvider from the ServerAuthenticationStateProvider type defined by Blazor, as this type has a method which is called by the CircuitHost to set the authentication state...

  • I did not peruse the code in your custom implementation of AuthenticationStateProvider, but I'd say that it has to contain logic that only pertains to authentication state, and nothing else (separation of concerns). And, yes, use it only if is necessary.

Hope this helps...

Tags:

Blazor