I am a beginner programmer with little experience in building complex applications. Currently I'm making a messenger using Python's FastAPI for the back-end. The main thing that I am trying to achieve within this project is a clean three-tier architecture.
My business logic layer consists of services: there's a MessageService, UserService, AuthService etc., handling their corresponding responsibilities.
One of the recent additions to the app has led to the injection of an instance of ChatService into the MessageService. Until this time, the services have only had repositories injected in them. Services have never interacted or knew about each other.
I'm wondering if injecting one element of business layer (a service) into another one is violating the three-tier architecture in any way. To clarify things more, I'll explain why, and how I got two services overlapped:
Inside the MessageService module, I have a method that gets all unread messages from all the chats where the currently authenticated user is a participant: get_unreads_from_all_chats. I conveniently have a method get_users_chats inside the ChatService, which fetches all the chats that have the current user as a member. I can then immediately use the result of this method, because it already converts the objects retrieved from the database into the pydantic models. So I decided to inject an instance of ChatService inside the MessageService and implement the get_unreads_from_all_chats method the following way (code below is inside the class MessageService):
async def get_unreads_from_all_chats(self, user: UserDTO) -> list[MessageDTO]: chats_to_fetch = await self.chat_service.get_users_chats(user=user) ...... I could, of course, NOT inject a service into another service and instead inject an instance of ChatRepository into the MessageService. The chat repository has a method that retrieves all chats where the user is a participant by user's id - this is what ChatService uses for its own get_users_chats. But is it really a big deal if I inject ChatService instead? I don't see any difference, but maybe somewhere in the future for some arbitrary function it will be much more convenient to inject a service, not a repository into another service. Should I avoid doing that for architectural reasons?
Does injecting a service into the service violate the three-tier architecture in any way?