Answer the question
In order to leave comments, you need to log in
How to get IHubContext in ConfigureServices?
How to get IHubContext in ConfigureServices, ASP.NET Core 2.1?
This implementation returns only null, and, accordingly, sending messages through the context does not work:
var provider = services.BuildServiceProvider();
using (var scope = provider.CreateScope())
{
IHubContext<CrashHub> crashHub = (IHubContext<CrashHub>)scope.ServiceProvider.GetService(typeof(IHubContext<CrashHub>));
GamesContext сrashService = new GamesContext(connection);
services.AddSingleton<IHostedService, CrashService>(s => new CrashService(crashHub, сrashService));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question