See: #30
It was previously possible to send messages to connected clients while inside of a grain (or elsewhere) by injecting the IActorProviderFactory. It left a little to be desired however, and required the user to know the internals of OrgnalR messaging. This PR exposes a couple of new classes to the consuming applications, which implement interfaces which are exposed by SignalR for this purpose:
IHubContextProvider
This interface (and accompanying class) exposes methods for getting a HubContext. This is the interface which should be injected into grains, or services which need to send messages to connected clients. It allows the application to address hubs by name, or by a marker interface.
HubContext : IHubContext
This class is provided by the above class and provides methods for interacting with clients connected to a specific Hub. The HubContext exposes methods for getting handles for sending messages to clients in bulk (by group, all clients, or all clients by user), or individually. It implements the IHubContext interface provided by SignalR
ClientMessageSender : IClientProxy
The ClientMessageSender class is the class which handles serializing messages and sending them off to the correct grains which will dispatch the messages to clients. It exposes a single "SendAsync" method which takes a method name (the method which will be invoked on the connected client), and the parameters to that method.
Usage (with hub name):
public class GameStateService
{
private readonly IHubContextProvider hubContextProvider;
public GameStateService(IHubContextProvider hubContextProvider)
{
this.hubContextProvider = hubContextProvider;
}
public void NotifyOfNewGameState(Guid gameId)
{
hubContextProvider
.GetHubContext("GameHub")
.Clients
.Group(gameId.ToString())
.SendAsync("NewGameStateAvailable", gameId);
}
}
Usage (with hub interface):
public class GameStateService
{
private readonly IHubContextProvider hubContextProvider;
public GameStateService(IHubContextProvider hubContextProvider)
{
this.hubContextProvider = hubContextProvider;
}
public void NotifyOfNewGameState(Guid gameId)
{
hubContextProvider
.GetHubContext<IGameHub>()
.Clients
.Group(gameId.ToString())
.SendAsync("NewGameStateAvailable", gameId);
}
}
See: #30 It was previously possible to send messages to connected clients while inside of a grain (or elsewhere) by injecting the
IActorProviderFactory
. It left a little to be desired however, and required the user to know the internals of OrgnalR messaging. This PR exposes a couple of new classes to the consuming applications, which implement interfaces which are exposed by SignalR for this purpose:IHubContextProvider
This interface (and accompanying class) exposes methods for getting a
HubContext
. This is the interface which should be injected into grains, or services which need to send messages to connected clients. It allows the application to address hubs by name, or by a marker interface.HubContext : IHubContext
This class is provided by the above class and provides methods for interacting with clients connected to a specific Hub. The HubContext exposes methods for getting handles for sending messages to clients in bulk (by group, all clients, or all clients by user), or individually. It implements the IHubContext interface provided by SignalR
ClientMessageSender : IClientProxy
The ClientMessageSender class is the class which handles serializing messages and sending them off to the correct grains which will dispatch the messages to clients. It exposes a single "SendAsync" method which takes a method name (the method which will be invoked on the connected client), and the parameters to that method.
Usage (with hub name):
Usage (with hub interface):