Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does SignalR use IList in its contracts and everywhere in its internals instead of IEnumerable?

Tags:

c#

signalr

I'm sending messages to individual users depending on their roles, to accomplish that I have the following piece of code:

public static void Add(Guid userId, IEnumerable<SnapshotItem> snapshot)
{
    var hub = GlobalHost.ConnectionManager.GetHubContext<FeedbackHub>();

    var items = ApplicationDbContext.Instance.InsertSnapshot(userId, Guid.NewGuid(), snapshot);

    foreach (var sendOperation in ConnectedUsers.Instance.EnumerateSendOperations(items))
    {
        hub.Clients.Users(sendOperation.Groups.SelectMany(x => x.Users).Select(x => x.Id).ToList()).OnDataFeedback(sendOperation.Items);
    }
}

I'm not sure why do I have to invoke .ToList() each time I need to send something, my backing store is HashSet<String> and I want SignalR to work with that type of store instead of converting it to List each time since it would obviously consume processing power and memory.

Since in the backstage SignalR is doing simple iteration over the argument users or connectionIds, wouldn't it be more wise to use IEnumerable instead of IList, I've looked into the SignalR sources, shouldn't be to hard to achieve? Is there a particular reason for using the IList?


Edit

Created an issue on SignalR github page, will have to wait for one of the actual devs in order to clear things out...

like image 601
Lu4 Avatar asked Sep 29 '22 22:09

Lu4


1 Answers

There's no good reason for this as far as I can see digging through the older source code. The irony of it is that the IList<string> gets handed into the MultipleSignalProxy class where it is promptly mapped to a different format using another LINQ expression and then that is .ToList()'d. So, based on that exact usage in the implementation, they really don't need anything more than IEnumerable<string>.

like image 135
Drew Marsh Avatar answered Oct 08 '22 04:10

Drew Marsh