I need to track to which group specific connection belongs. I use Redis backplane and I have read the RedisHubLifetimeManager
code. I see that they use IRedisFeature
to store groups to which specific connection belongs.
I don't want to store the same information twice. But there is no any documentation how the Features
collection works. Where the data is stored? Can I be sure that this data is not modified by e.g. user?
I want to use it as below:
public class MessagingHub : Hub
{
private const string RECEIVE_MESSAGE_METHOD = "ReceiveMessage";
public async Task SendMessageAsync(SendMessageDto sendMessageDto)
{
var feature = Context.Features.SingleOrDefault(p => p.Key.Name == "IRedisFeature").Value;
var groups = feature.GetType().GetProperty("Groups")?.GetValue(feature) as HashSet<string>;
if (groups is null || !groups.Contains(sendMessageDto.ConversationId))
return;
await Clients.Group(sendMessageDto.ConversationId).SendAsync(RECEIVE_MESSAGE_METHOD);// rest omitted
}
}
But I'm not sure if I can rely on HubCallerContext.Features
collection and on IRedisFeature
. Can I? Is that secure (nobody can modify it, except SignalR hub)? How the HubCallerContext.Features
works?