startit/Emne 3/DependencyInversionPrinciple/DIP.ChatServer/ChatServer.cs

28 lines
464 B
C#
Raw Permalink Normal View History

2025-01-06 14:49:31 +01:00
namespace DIP.ChatServer;
2025-01-06 14:04:39 +01:00
public class ChatServer
{
2025-01-08 10:32:47 +01:00
private readonly List<IChatClient> _clients;
2025-01-06 14:04:39 +01:00
public ChatServer()
{
2025-01-08 10:32:47 +01:00
_clients = new List<IChatClient>();
2025-01-06 14:04:39 +01:00
}
2025-01-08 10:32:47 +01:00
public void Broadcast(IChatClient client, string message)
2025-01-06 14:04:39 +01:00
{
foreach (var chatClient in _clients)
{
if (chatClient != client)
{
chatClient.Receive(message);
}
}
}
2025-01-08 10:32:47 +01:00
public void Register(IChatClient client)
2025-01-06 14:04:39 +01:00
{
_clients.Add(client);
}
}