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

Bind classes which depends on each other in a subscope [QUESTION] #419

Open
imrepapp opened this issue Sep 7, 2020 · 0 comments
Open

Bind classes which depends on each other in a subscope [QUESTION] #419

imrepapp opened this issue Sep 7, 2020 · 0 comments
Assignees

Comments

@imrepapp
Copy link

imrepapp commented Sep 7, 2020

Hi,

when I try to add two bindings in a subscope which depends on each other the injection does not work. (it works if I add them to the rootScope)

What did I miss?

Thanks

KTP.openRootScope()
    .openSubScope(SUB_SCOPE) //if remove this line it is working
    .installModules(
        module {
            bind<Foo>().toProvider(FooProvider::class)

            bind<Bar>().toProvider(BarProvider::class)
        }
    )
    .inject(this)

interface Foo {
    val text: String
}

@Singleton
@ProvidesSingletonInScope
//@InjectConstructor //didn't help
class FooProvider: Provider<Foo> {
    override fun get() = object : Foo {
        override val text: String = "Foo"
    }
}

interface Bar {
    val fooInstance: Foo
}

@Singleton
@ProvidesSingletonInScope
@InjectConstructor
class BarProvider(
    val injectedFoo: Foo
): Provider<Bar> {
    override fun get() = object : Bar {
        override val fooInstance: Foo = injectedFoo
    }
}

RuntimeException:
toothpick.locators.NoFactoryFoundException: No factory could be found for class com.example.Foo. Check that the class has either a @Inject annotated constructor or contains @Inject annotated members.
Caused by: java.lang.ClassNotFoundException: com.example.Foo__Factory

@dlemures dlemures self-assigned this Oct 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants