72 lines
2.0 KiB
Kotlin
72 lines
2.0 KiB
Kotlin
package chats.di
|
|
|
|
import android.content.Context
|
|
import chats.data.remote.api.ChatApi
|
|
import chats.data.remote.signalr.ChatHubClient
|
|
import chats.data.repository.ChatRepositoryImpl
|
|
import chats.data.signalr.MessageSignalRHandler
|
|
import chats.domain.repository.ChatRepository
|
|
import core.database.data.ChatDatabase
|
|
import core.database.data.ChatDao
|
|
import core.database.data.MessageDao
|
|
import core.network.ServerConfig
|
|
import core.security.TokenManager
|
|
import dagger.Module
|
|
import dagger.Provides
|
|
import dagger.hilt.InstallIn
|
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
import dagger.hilt.components.SingletonComponent
|
|
import retrofit2.Retrofit
|
|
import javax.inject.Singleton
|
|
|
|
@Module
|
|
@InstallIn(SingletonComponent::class)
|
|
object ChatModule {
|
|
|
|
@Provides
|
|
@Singleton
|
|
fun provideChatApi(retrofit: Retrofit): ChatApi {
|
|
return retrofit.create(ChatApi::class.java)
|
|
}
|
|
|
|
@Provides
|
|
@Singleton
|
|
fun provideMessageSignalRHandler(
|
|
hubClient: ChatHubClient,
|
|
messageDao: MessageDao,
|
|
chatDao: ChatDao,
|
|
serverConfig: ServerConfig,
|
|
tokenManager: TokenManager
|
|
): MessageSignalRHandler {
|
|
return MessageSignalRHandler(hubClient, messageDao, chatDao, serverConfig, tokenManager)
|
|
}
|
|
|
|
@Provides
|
|
@Singleton
|
|
fun provideChatDao(database: ChatDatabase): ChatDao {
|
|
return database.chatDao()
|
|
}
|
|
|
|
@Provides
|
|
@Singleton
|
|
fun provideChatRepository(
|
|
api: ChatApi,
|
|
tokenManager: TokenManager,
|
|
serverConfig: ServerConfig,
|
|
messageDao: MessageDao,
|
|
chatDao: ChatDao,
|
|
database: ChatDatabase,
|
|
hubClient: ChatHubClient,
|
|
signalRHandler: MessageSignalRHandler,
|
|
@ApplicationContext context: Context
|
|
): ChatRepository {
|
|
return ChatRepositoryImpl(api, tokenManager, serverConfig, messageDao, chatDao, database, hubClient, signalRHandler, context)
|
|
}
|
|
|
|
@Provides
|
|
@Singleton
|
|
fun provideChatHubClient(): ChatHubClient {
|
|
return ChatHubClient()
|
|
}
|
|
}
|