What's the recommended approach to binding and int...
# kotlin-inject
m
What's the recommended approach to binding and internal implementation to a interface, So that module A consumes Module B can expose an interface from B without needing to expose its impl?
e
More concrete examples would be helpful but the handwavy answer is parent components can be an interface with the impl living somewhere else, you just need to provide methods for the types you are using
m
Ok I'll try to use a concrete example:
Copy code
Module A

interface ApplicationComponent
( The implementation live on different sourcets but thats not important I believe
Copy code
Module B

interface Repository

internal class RepositoryImpl(more internal deps): Repository

interface ModuleBComponent {
   @Provides 
   fun provideRepo(impl:RepositoryImpl): Repository = iml
    (This obcs does nto compile
}
The usual pattern I go with is :
Copy code
AplicationComponent: ModuleBComponent
Ive tried a fiew works around with abstract classes bu eventually ModuleA generated code tries to reference the internal class so compilation is not possible
e
right, if you think about it, implementing ModuleBComponent requires referencing RepositoryImpl. One thing you can do is
Copy code
interface ModuleBComponent {
    val repo: Repository
}

@Component
abstract class MyoduleBComponentImpl : ModuleBComponent {
    @Provides 
   fun provideRepo(impl:RepositoryImpl): Repository = impl
}

...

@Component
abstract class ApplicationComponent(@Component val moduleB: ModuleBComponent)
with the downside is you'll need different scopes for the 2 components, which may or may not be fine depending on how circular your dependencies are
m
Interesting, will deffo give it a try at this tomorrow, cheers!
e
long-term I do want to handle restricted visibility better, but it's tricky because you have to generate bridge code to call into non-public methods
🙌 1
👀 1
m
Yeah soudns about right. Thanks for all the effort btw!