V
V
vanixachatryan2018-12-24 21:48:04
ASP.NET
vanixachatryan, 2018-12-24 21:48:04

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 question

Ask a Question

731 491 924 answers to any question