Reputation: 1029
I have a class that I am doing property injection.
Calling methods of this service object does nothing, no errors, exceptions, etc.
When I check to see if the service is null, it is. This seems like this should be a null exception.
I am checking the service null in a SignalR "ON" call back so it looks like there maybe a race condition, but
My solution was to change it to a constructor inject, but I am wondering why this doesn't work.
Upvotes: 3
Views: 2798
Reputation: 31
I ran into the same issue.
From what I can tell, [Inject] works with razor pages. If you want to inject into a class, you need to use the constructor method.
See section about IJSRuntime: https://learn.microsoft.com/en-us/aspnet/core/blazor/call-javascript-from-dotnet?view=aspnetcore-3.1
Upvotes: 3