Skip to content

check for duplicate bindings between child and parent components #445

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

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

hectorups
Copy link
Contributor

Fixes issue #444

@hectorups
Copy link
Contributor Author

@evant one of the integration test is failing after the changes to compile:

@Component abstract class ParentComponent {
    abstract val parentNamedFoo: NamedFoo

    @Provides
    protected fun foo() = NamedFoo("parent")

    val Foo.binds: IFoo
        @Provides get() = this
}

@Component abstract class SimpleChildComponent1(@Component val parent: ParentComponent) {
    abstract val namedFoo: NamedFoo

    val BarImpl.binds: IBar
        @Provides get() = this

    abstract val foo: IFoo
}

In this example the binding NamedFoo is provided by both the parent and child components, creating a situation we're trying to avoid. Currently, a type inside SimpleChildComponent1 that requires NamedFoo will receive the one from the parent. In my opinion, this is arbitrary and likely unwanted, especially in large projects with complex dependency graphs. We should enforce having only one type binding per dependency graph. If multiple bindings of the same type are necessary, qualifiers, type-aliases, or multibindings can be used.

@evant
Copy link
Owner

evant commented Oct 7, 2024

I don't see see how the type is provided multiple times in that example? Both should be getting an instance from @Provides protected fun foo() right?

@hectorups
Copy link
Contributor Author

I don't see see how the type is provided multiple times in that example? Both should be getting an instance from @Provides protected fun foo() right?

👍 my mental model of Dagger, where Components don't use @provides, caused my confusion.

@hectorups hectorups requested a review from evant October 8, 2024 23:16
@evant evant enabled auto-merge (squash) October 9, 2024 17:09
@evant evant merged commit 5d3afe7 into evant:main Oct 9, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants