Skip to content

How to test a custom AuthenticationStateProvider? #1666

Answered by linkdotnet
TDroogers asked this question in Q&A
Discussion options

You must be logged in to vote

I am so blind:

[Inject] private CustomStateProvider AuthenticationStateProvider { get; set; } = default!;

This will ask for a CustomStateProvider but you didn't directly register one. You told the container only to provide CustomStateProvider if someone asks for a AuthenticationStateProvider.

That said, you can easily fix your issue by:

-[Inject] private CustomStateProvider AuthenticationStateProvider { get; set; } = default!;
+[Inject] private AuthenticationStateProvider AuthenticationStateProvider { get; set; } = default!;

Alternatively, you register CustomStateProvider additionally in the container:

Services.AddScoped<CustomStateProvider>();
Services.AddScoped<AuthenticationStateProvider>

Replies: 1 comment 4 replies

Comment options

linkdotnet
Feb 2, 2025
Maintainer Sponsor

You must be logged in to vote
4 replies
@scottsauber
Comment options

@TDroogers
Comment options

@linkdotnet
Comment options

linkdotnet Feb 3, 2025
Maintainer Sponsor

Answer selected by TDroogers
@TDroogers
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants