Can't wrap my head around this piece of code of an example.
There is an interface that looks like this:
using System.Threading.Tasks;
namespace NotificationHub
{
public interface INotifyHubClient
{
Task NotifyClient(string type);
}
}
And a class that uses the interface:
using Microsoft.AspNetCore.SignalR;
namespace NotificationHub
{
public class NotificationHub : Hub<INotifyHubClient>
{
}
}
In a controller it is simply used like this:
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System;
namespace NotificationHub.Controllers
{
[Route("api/[controller]")]
public class NotificationController : Controller
{
private IHubContext<NotificationHub, INotifyHubClient> _hubContext;
public NotificationController(IHubContext<NotificationHub, INotifyHubClient> hubContext)
{
_hubContext = hubContext;
}
[HttpPost]
public string Post([FromBody]string message)
{
_hubContext.Clients.All.NotifyClient(message);
return "Success";
}
}
}
Why does this work without a proper implementation for NotifyClient?