Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inject repository using hilt #33

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.swent.echo.di

import com.github.swent.echo.authentication.AuthenticationService
import com.github.swent.echo.data.repository.Repository
import com.github.swent.echo.data.repository.RepositoryImpl
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import io.github.jan.supabase.SupabaseClient
Expand Down Expand Up @@ -29,6 +31,8 @@ class DependencyInjectionTest {

@Inject lateinit var authenticationService: AuthenticationService

@Inject lateinit var repository: Repository

@Before
fun setUp() {
// This tells Hilt to inject the [supabaseClient] and [authenticationService] fields.
Expand All @@ -48,4 +52,9 @@ class DependencyInjectionTest {
fun testAuthenticationServiceInjection() {
assertEquals(SimpleAuthenticationService::class.java, authenticationService::class.java)
}

@Test
fun testRepositoryInjection() {
assertEquals(RepositoryImpl::class.java, repository::class.java)
}
}
24 changes: 24 additions & 0 deletions app/src/main/java/com/github/swent/echo/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.swent.echo.di

import android.app.Application
import com.github.swent.echo.data.repository.Repository
import com.github.swent.echo.data.repository.RepositoryImpl
import com.github.swent.echo.data.repository.datasources.RemoteDataSource
import com.github.swent.echo.data.repository.datasources.Supabase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.github.jan.supabase.SupabaseClient

@Module
@InstallIn(SingletonComponent::class)
object RepositoryModule {

@Provides
fun provideRepository(application: Application, supabaseClient: SupabaseClient): Repository {
val remoteDataSource: RemoteDataSource = Supabase(supabaseClient)

return RepositoryImpl(remoteDataSource)
}
}