Test

As the official documentation states, SignalR is a library for ASP.NET developers that simplifies the process of adding real-time web functionality to applications. Real-time web functionality is the ability to have server code push content to connected clients instantly as it becomes available, rather than having the server wait for a client to request new data. SignalR can be used to add any sort of “real-time” web functionality to your ASP.NET application.

SignalR uses “hub” classes, which are similar to controller classes, but, as well as allowing the client to call methods on the hub, it also provides a simple API for creating server-to-client remote procedure calls (RPC) that call JavaScript functions in client browsers from server-side .NET code.

Each hub has an interface, where its methods are defined, and a concrete implementation. Once you define a SignalR subscription in the microservice’s yaml file, a new method will be added to the interface, which you will implement in the concrete hub.

All hubs and hub contracts are contained within the Hubs folder.


public class MyMethodParams
{
    public int MyProperty { get; set; }
}

public interface IMyHub
{
    Task MyMethod(MyMethodParameters @params);
}

public class MyHub : TaskHub<MyHub, IMyHub>, IMyHub
{
    public MyHub(IHubContext<MyHub, IMyHub> hubContext) : base(hubContext)
    {
    }

    public async Task MyMethod(MyMethodParameters @params)
    {
        // Implementation example
        return _context.Clients.All.MyMethod(@params);
    }
}