https://kotlinlang.org logo
#dagger
Title
# dagger
j

Jason Ankers

03/15/2021, 2:49 AM
Is it permitted to write extension methods/properties on a custom component? I.e im using this to reduce the verbosity of accessing an entrypoint.
Copy code
val AuthenticatedComponent.entryPoint: AuthenticatedComponentEntryPoint
    get(): AuthenticatedComponentEntryPoint {
        return EntryPoints.get(this, AuthenticatedComponentEntryPoint::class.java)
    }
And then I can inject with:
Copy code
private val myRepository = authManager.component!!.entryPoint.getMyRepository()
Edit: Just realized EntryPoints are specific to Hilt and this is a dagger channel
j

Jeremy

03/15/2021, 11:47 PM
If it compiles and runs I think its permitted
Is this Android? You don't need any dependencies from application/activity scopes?
j

Jason Ankers

03/16/2021, 1:35 AM
Yeah its Android,
AuthenticatedComponent
is a child of
SingletonComponent
j

Jeremy

03/16/2021, 8:54 PM
You may consider
EntryPointAccessors.fromApplicaton(context, class)
see javadoc
4 Views