Colton Idle
11/03/2020, 4:04 AMPablo
11/04/2020, 1:07 PM@ContributeAndroidInjection
and then if my Activity2 wants to inject Fragment1
Why I need to implement HasAndroidInjector and do the
@Inject lateinit var androidInjector: DispatchingAndroidInjector<Any>
override fun androidInjector(): AndroidInjector<Any> = androidInjector
to be able to use a Fragment that is already with @ContributeAndroidInjection
? If I remove this two lines it says :
RunTimeException:Unable to resume activity {MyActivity}: java.lang.IllegalArgumentException: No injector factory bound for Class<MyClass>I thought that if I have this:
@ContributesAndroidInjector(
modules = [ FragmentProvider::class]
)
fun bindMyActivity2: Activity2
It would work anyways, because I've add as a modules a module that has inside the @ContributesAndroidInjector
with that Fragment...
Is it because I need that `hasAndroidInjector`when I want to provide injection into a inner Fragment?Colton Idle
11/06/2020, 9:17 PMcoroutinedispatcher
11/08/2020, 4:49 PMKshitij Patil
11/20/2020, 8:38 AMColton Idle
11/28/2020, 9:53 PMbodo
12/02/2020, 12:50 PMkapt(...)
another example is when i annotate a constructor of a class with @Inject in a library oder feature module, do i also have to run the annotation processor in each of this modules
i am asking because then i have to run annotation processing in nearly every module which is not really performantChristopher Elías
12/10/2020, 2:21 PMclass MyApp(): Application(), LoginComponentProvider, RegisterComponentProvider, RecoverPasswordComponentProvider {
// Reference to the application graph that is used across the whole app
val appComponent by lazy {
// Creates an instance of AppComponent using its Factory constructor
// We pass the applicationContext that will be used as Context in the graph
DaggerMyAppComponent.factory().create(applicationContext)
}
override fun provideLoginComponent(): LoginComponent {
return appComponent
.loginComponent()
.create()
}
override fun provideRegisterComponent(): RegisterComponent {
return appComponent
.registerComponent()
.create()
}
override fun provideRecoverPasswordComponent(): RecoverPasswordComponent {
return appComponent
.recoverPasswordComponent()
.create()
}
... On every new feature module I will have to implement its provider
}
Is any pattern or better way to improve this? Im doing this based on the official documentaton for dagger in android https://developer.android.com/training/dependency-injection/dagger-multi-moduleblakelee
12/23/2020, 1:40 AMclass MyClass @Inject constructor(
@Tablet isTablet: Boolean
)
Then in my module I have something like
@Provides
@Tablet
fun provideIsTablet(context: Context): Boolean = someWayToTellIfTablet
Is there a way to create an annotation like this without have to use @Named("Tablet")
Colton Idle
01/01/2021, 4:39 AMApplication
or Activity
."
Can anyone explain what that means?
Edit: I think this is part of the lingo of dagger that I haven't picked up yet, but it seems like it's pretty widely accepting that "bindings" in the context of dagger means "types that are available to you". If so... Bindings for Application or Activity... do they actually mean Context?Colton Idle
01/03/2021, 2:05 AMSlackbot
01/06/2021, 1:15 AMNicholas Doglio
01/12/2021, 1:20 AMbuild.gradle
file to enable kapt to work properly when using JDK 15 to build? I keep getting this error `package javax.annotation.processing does not exist import javax.annotation.processing.Generated`whenever I try to build. My config is the following:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
kapt {
javacOptions {
option("-source", "8")
option("-target", "8")
}
}
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.ndoglio.daggerkapt"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '<http://proguard-rules.pro|proguard-rules.pro>'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.dagger:dagger:2.30.1'
kapt 'com.google.dagger:dagger-compiler:2.30.1'
}
Manuel Vivo
01/18/2021, 1:08 PMMassimo Carli
01/23/2021, 4:31 PM@AssistedInject
class.
class CalculatorImpl @AssistedInject constructor(
private val logger: Logger,
@Assisted private val increment: Int
) : Calculator {
override fun addOne(a: Int) = a.inc().apply {
logger.log("New value is $this")
}
}
The @AssistedFactory
is the following
@AssistedFactory
interface CalculatorImplFactory {
fun create(
inc: Int
): CalculatorImpl
}
When I try to inject the CalculatorImplFactory
in an Activity like this
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
@Inject
lateinit var calculatorFactory: CalculatorImplFactory
// ...
}
When I build I get a
CalculatorImplFactory cannot be provided without an @Provides-annotated method.
The documentations says that Dagger will create the implementation for the assisted factory and provide a binding for it.
but this doesn't seem to be true. What am I missing? ThanksTiago Nunes
02/05/2021, 11:32 AMColton Idle
02/08/2021, 8:36 PM@Inject var taxes: Taxes? = null
Unfortunately it needs to be nullable as the provider is nullable, but I get an error saying Dagger does not support injection into private fields... which leads me to do
@set:Inject var taxes: Taxes? = null
and everything works. I could have sworn that this "workaround" wasn't needed for latest versions of dagger. Am I missing something?Sinan Gunes
02/15/2021, 12:43 PM@Assisted
parameter should return same object.Colton Idle
02/18/2021, 3:11 PMAmrita Chaturvedi
02/25/2021, 6:55 AMManuel Vivo
03/01/2021, 5:17 PMescodro
03/03/2021, 6:45 PM--debug
it only gives me the default:
Execution failed for task ':app:kaptDebugAndroidTestKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
I’m migrating from Koin to Hilt but this is blocking me once I want to do some end to end tests in my application.
Thanks a lot in advance! ❤️Lucien Guimaraes
03/09/2021, 12:16 PM@HiltViewModel
annotation. How would you achieve it only with Dagger ?Jason Ankers
03/15/2021, 2:49 AMval AuthenticatedComponent.entryPoint: AuthenticatedComponentEntryPoint
get(): AuthenticatedComponentEntryPoint {
return EntryPoints.get(this, AuthenticatedComponentEntryPoint::class.java)
}
And then I can inject with:
private val myRepository = authManager.component!!.entryPoint.getMyRepository()
Edit: Just realized EntryPoints are specific to Hilt and this is a dagger channelmiqbaldc
03/15/2021, 4:46 AM@ApplicationContext
in DFM (dynamic feature module)? or should we provide application context manually?
If we need to provide manually in DFM, is there any reference you guys can point me out?
DFM - error: [Dagger/MissingBinding] @dagger.hilt.android.qualifiers.ApplicationContext android.content.Context cannot be provided without an @Provides-annotated method.
opened an issue here: https://github.com/google/dagger/issues/2477
knthmn
03/15/2021, 9:37 AM@Provides
it?André Thiele
03/20/2021, 5:17 PMFunkyMuse
03/22/2021, 10:35 PMAndré Thiele
04/04/2021, 8:39 AMSlackbot
04/09/2021, 7:15 AM