dagger-reflect icon indicating copy to clipboard operation
dagger-reflect copied to clipboard

dagger-reflect more strict than dagger-compiler (scopes)

Open plnice opened this issue 5 years ago • 1 comments

In our application we have structure similar to this one:

@Singleton
@Component
interface MainComponent {
  fun feature(): FeatureComponent
}

@Subcomponent
interface FeatureComponent {
  fun plus(module: SubFeatureModuleA): SubFeatureComponentA
  fun plus(module: SubFeatureModuleB): SubFeatureComponentB
}

@Scope
@Retention(RUNTIME)
annotation class SubFeatureScopeA

@Module
class SubFeatureScopeA {
	
  @Provides
  @SubFeatureScopeA
  fun provideSomething(something: Something): ISomething = something

}

@Subcomponent(modules = [SubFeatureModuleA::class])
@SubFeatureScopeA
interface SubFeatureComponentA {
  fun inject(fragment: SubFeatureAFragment)
}

(sometimes also FeatureComponent has some modules defined, but it's irrelevant in this case)

For such case, we get following exception in runtime:

Caused by: java.lang.IllegalStateException: Scope with annotations [@com.myapp.SubFeatureScopeA()] may not depend on unscoped
at dagger.reflect.Scope$Builder.<init>(Scope.java:167)
at dagger.reflect.ComponentScopeBuilder.get(ComponentScopeBuilder.java:115)
at dagger.reflect.ComponentInvocationHandler$SubcomponentMethodInvocationHandler.invoke(ComponentInvocationHandler.java:180)
at dagger.reflect.ComponentInvocationHandler.invoke(ComponentInvocationHandler.java:70)
at java.lang.reflect.Proxy.invoke(Proxy.java:913)
at $Proxy44.plus(Unknown Source)

while the dagger-compiler (2.26) allows such construct and works fine.

plnice avatar Jan 31 '20 09:01 plnice

Same issue.

naixx avatar Mar 28 '20 14:03 naixx