Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

When nested overriding modules provide the same binding, outermost override should "win" #179

Closed
adennie opened this issue Mar 9, 2013 · 1 comment

Comments

@adennie
Copy link
Contributor

adennie commented Mar 9, 2013

A module can't override an included module's provider for a particular type if the included module also overrides a third module. For example:

public static class Thing {
}

@Module
public static class Module1 {
}

@Module(overrides= true, includes = Module1.class)
public static class Module2 {
   @Provides
    public Thing provideThing() {
        return new Thing();
    }
}

@Module(overrides= true, includes = Module2.class)
public static class Module3 {
   @Provides
    public Thing provideThing() {
        return new Thing();
    }
}

This results in "Duplicate bindings for Thing: Module3.provideThing(), Module2.provideThing()." This is because FullGraphProcessor.processCompleteModule detects "clobbering" within the map of override bindings and records it as an error.

It seems like it should be possible to keep track of the hierarchy of the modules, and have the most-overriding module "win".

@swankjesse
Copy link
Member

No, I don't think this complexity is worthwhile. Module overrides support only two levels, most commonly used for production and test. Precedence rules are not worth the complexity of implementation and we want to discourage users from building apps that would need them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants