title: Multiple Single Chat Rooms using SignalR (ASP.NET Core)
body: <p>I've to create a Chat between two users (a hired person and a hirer). It doesn't need to be real-time but using SignalR I might accomplish that, but no problem.</p>
  
  <p>I'll store the previous messages on a database to retrieve everytime the chat was open.</p>
  
  <p>So, I need to broadcast a message only between two users, but, a user can have multiple chat rooms with differente people (but only 1:1).</p>
  
  <p>How can I accomplish that logic in my code? Do I have to use Groups? And if so, how can I store the information that "this user has to send message to that user", on a 1:1 chat, and not broadcast to everyone?</p>
  
  <p>My ChatHub class:</p>
  
  <pre><code>public class ChatHub : Hub
  {
      private readonly IChatAppService _chatAppService;
  
      public ChatHub(IChatAppService chatAppService)
      {
          _chatAppService = chatAppService;
      }
  
      public string GetConnectionId()
      {
          return Context.ConnectionId;
      }
  
      public async Task SendMessage(ChatAddVM message, string userName)
      {
          string connectionId = GetConnectionId();
  
          await Clients.Client(connectionId).SendAsync("broadcastMessage", userName, message.Message);
          //USED TO SAVE THE MESSAGE ON DB
          await _chatAppService.CreateMessage(message);
      }
  }
  </code></pre>