SignalR.Orleans icon indicating copy to clipboard operation
SignalR.Orleans copied to clipboard

Expose hub interface for use within HubContext

Open dealproc opened this issue 5 years ago • 2 comments

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.

dealproc avatar Feb 21 '19 18:02 dealproc

Not sure this is desired... @claylaut may have some extra thoughts on it...

galvesribeiro avatar May 20 '19 22:05 galvesribeiro

@galvesribeiro it's nice to have feature.

claylaut avatar May 24 '19 08:05 claylaut