I tried using the jakarta.inject.Singleton inside my Singleton Module
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import jakarta.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
class ValidationModule {
@Provides
@Singleton
fun provideEmailValidator(
): EmailValidator {
return EmailValidatorImpl()
}
@Provides
@Singleton
fun providePasswordValidator(
): PasswordValidator {
return PasswordValidatorImpl()
}
}
but I got this error when i tried to build
error: [Dagger/IncompatiblyScopedBindings] com.besa.shelflife.ShelfLifeApplication_HiltComponents.SingletonC scoped with @Singleton may not reference bindings with different scopes:
public abstract static class SingletonC implements ShelfLifeApplication_GeneratedInjector,
^
@Provides @jakarta.inject.Singleton com.besa.core.domain.validation.EmailValidator com.besa.core.di.ValidationModule.provideEmailValidator()
@Provides @jakarta.inject.Singleton com.besa.core.domain.validation.PasswordValidator com.besa.core.di.ValidationModule.providePasswordValidator()
after switching to javax.inject.Singleton the issue got fixed
I tried using the
jakarta.inject.Singletoninside my Singleton Modulebut I got this error when i tried to build
after switching to
javax.inject.Singletonthe issue got fixed