SignalR.Orleans
SignalR.Orleans copied to clipboard
Expose hub interface for use within HubContext
Within this example code:
public class UserNotificationGrain : Grain<UserNotificationState>, IUserNotificationGrain
{
private HubContext<IUserNotificationHub> _hubContext;
public override async Task OnActivateAsync()
{
_hubContext = GrainFactory.GetHub<IUserNotificationHub>();
// some code...
await _hubContext.User(this.GetPrimaryKeyString()).SendSignalRMessage("Broadcast", State.UserNotification);
}
}
It would be decent if the IUserNotificationHub
interface could have methods that are implemented on the client to be exposed to the Grain code.
In the case of the example code, the changes would look something like:
public interface IUserNotificationHub
{
task Broadcast(UserNotification);
}
public class UserNotificationGrain : Grain<UserNotificationState>, IUserNotificationGrain
{
private HubContext<IUserNotificationHub> _hubContext;
public override async Task OnActivateAsync()
{
_hubContext = GrainFactory.GetHub<IUserNotificationHub>();
// some code...
await _hubContext.User(this.GetPrimaryKeyString()).Broadcast(State.UserNotification);
}
}
Which would cleanup the server code.
Not sure this is desired... @claylaut may have some extra thoughts on it...
@galvesribeiro it's nice to have feature.