Search code examples
androidfirebasemvvmfirebase-cloud-messagingandroid-mvvm

Where to place the MyFirebaseMessagingService file in Android project MVVM?


I have an Android project where I use MVVM. This is the structure:

src
 \_ domain
     \_ model
     \_ repository
          \_ ItemsRepository
 \_ data
     \_ repository
          \_ ItemsRepositoryImpl
 \_ presentations
     \_ items
          \_ ItemsScreen
          \_ ItemsViewModel

Today I have implemented Firebase Cloud Messaging and I have created a MyFirebaseMessagingService class. Where in this structure should I place such a file? Where is the place that belongs to?


Solution

  • First thing here is that MVVM is a pattern and it is used in the presentation layer.

    What you are seeking is where the service belongs when you are using a Clean Architecture layer based module.

    The MyFirebaseMessagingService class doest not belongs to presentation layer obviously (because it has nothing to do with the presentation of your app).

    It should not be in the domain layer because the domain layer should have only use cases, repository interfaces and model. + the service has nothing to do with business logic

    So, the last layer is the data one and this is where the service should be. If the service communicate with firebase to send / retrieve data it mean that the service is considered like a Data Source. The purpose of repositories is to aggregate those data sources and to build a domain model.