I have a Core Android Library where I'm defining number of interfaces and its default implementations. All of them are exposed by CoreModule which is defined in CoreComponent.`
Core module
@Module
public class CoreModule {
@Provides
public IAuthenticationViewExtension provideToolsViewExtension() {
return new AuthenticationViewExtension();
}
@Provides
public ISettingsViewExtension provideISettingsViewExtension() {
return new SettingsViewExtension();
}
}
Core component
@Component( modules = {CoreModule.class})
public interface CoreComponent {
CoreComponent coreComponent();
void inject(BaseLauncher baseLauncher);
ISettingsViewExtension iSettingsViewExtension();
}
All implementations are injected only in Core library.
There is also a Ui library which is dependent on Core library. Additionally, Ui library can provide a custom implementation to some of interfaces defined in Core library.
├── Ui Library
└── Core Library
└── Core Library
In order to achieve the goal I have created a custom @component and @module in Ui library
@Component(dependencies = {UiComponent.class},
modules = {UiModule.class})
public interface UiComponent {
}
@Module
public class DemoUiModule {
@Provides
public IAuthenticationViewExtension provideToolsViewExtension() {
return new CustomAuthenticationViewExtension();
}
}
I think that the best solution to provide a custom implementation to Core library is be using a Subcomponent but, unfortunately, it doesn't seem possible because the Core Library has no visibility to the other libraries (Ui library and it's @component) , so I can't inject any of custom implementations in Core library. Any help?