Original post

For example lets say we have an online chatroom. Users can join a room and post messages there and the messages are delivered to other users in the room via some realtime delivery mechanism.

So we have a roomService struct.

type roomService struct {
    room      messagerooms.RoomRepository 
    message   messagerooms.MessageRepository 
    publisher pubsub.Service 

Here roomService is dependent on the pubsub service because every time a new message is posted, that message is sent to the pubsub system for distributing accross the room members via maybe an websocket connection.

My Problem here is that if an user tries to subscribe to the message streams for a room, before subscribing the user to the stream, the pubsub service needs to check if that user is actually part of the room. And thus the pubsub service becomes dependent on the roomService for deciding if the user is part of the room, which is creating a circular dependency.

So how to handle situations like this?