V
V
vanixachatryan2018-12-26 19:52:01
ASP.NET
vanixachatryan, 2018-12-26 19:52:01

Why is SignalR Core running in a service being ignored?

register service:

var provider = services.BuildServiceProvider();
            using (var scope = provider.CreateScope())
            {
                IHubContext<CrashHub> crashHub = (IHubContext< CrashHub > )provider.GetService<IHubContext<CrashHub>>();
                GamesContext сrashService = new GamesContext(connection);
                services.AddSingleton<IHostedService, CrashService>(s => new CrashService(crashHub, сrashService, Configuration));
            }

line
IHubContext<CrashHub> crashHub = (IHubContext< CrashHub > )provider.GetService<IHubContext<CrashHub>>();
is responsible for getting the hub context, then I pass it to my service.
This is what the hub constructor looks like:
public CrashService(IHubContext<CrashHub> hubContext, GamesContext db, IConfiguration configuration)
        {
            _db = db;
            _hubContext = hubContext;
        }

There are no errors, everything starts. I'm trying to send a message
await _hubContext.Clients.All.SendAsync("wait", 2);
, but it is not sent. What to do about it, what could be the reason?

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