This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import com.android.build.api.transform.DirectoryInput; | |
import com.android.build.api.transform.Format; | |
import com.android.build.api.transform.QualifiedContent; | |
import com.android.build.api.transform.Status; | |
import com.android.build.api.transform.Transform; | |
import com.android.build.api.transform.TransformException; | |
import com.android.build.api.transform.TransformInput; | |
import com.android.build.api.transform.TransformInvocation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> createSingleton(provider: () -> T): () -> T { | |
val lazy by kotlin.lazy(provider) | |
return { lazy } | |
} | |
fun <T> createLazy(provider: () -> T): dagger.Lazy<T> { | |
val lazy by kotlin.lazy(provider) | |
return dagger.Lazy { lazy } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KotlinParentComponent : ParentComponent { | |
override fun getString(): String = SubcomponentModule.getStringFromSubcomponent(ChildComponentFactory()) | |
private inner class ChildComponentFactory : ChildComponent.Factory { | |
override fun create(string: String): ChildComponent = ChildComponentImpl(string) | |
} | |
private inner class ChildComponentImpl( | |
private val childString: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Qualifier | |
annotation class DefinedInChildComponent | |
@Module(subcomponents = [ChildComponent::class]) | |
object SubcomponentModule { | |
@Provides | |
fun getStringFromSubcomponent( | |
subcomponent: ChildComponent.Factory | |
): String { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KotlinParentComponent( | |
private val string: String | |
) : ParentComponent { | |
override fun createChildComponent(): ChildComponent = ChildComponentImpl() | |
private inner class ChildComponentImpl : ChildComponent { | |
override fun getString(): String = this@KotlinParentComponent.string | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
interface ParentComponent { | |
fun createChildComponent(): ChildComponent | |
@Component.Factory | |
interface Factory { | |
fun create( | |
@BindsInstance string: String | |
): ParentComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimplifiedKotlinCircularComponent : CircularComponent { | |
private lateinit var apiServiceProviderDelegate: () -> ApiService | |
private val apiServiceProvider = { apiServiceProviderDelegate() } | |
private val authenticatorProvider = { Authenticator(createLazy(apiServiceProvider)) } | |
private val httpClientProvider = { HttpClient(authenticatorProvider()) } | |
init { | |
apiServiceProviderDelegate = createSingleton { ApiService(httpClientProvider()) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KotlinCircularComponent : CircularComponent { | |
private val apiServiceProvider = DelegateFactory<ApiService>() | |
private val authenticatorProvider = { Authenticator(createLazy(apiServiceProvider)) } | |
private val httpClientProvider = { HttpClient(authenticatorProvider()) } | |
init { | |
val delegate = createSingleton { ApiService(httpClientProvider()) } | |
DelegateFactory.setDelegate(apiServiceProvider, delegate) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HttpClient @Inject constructor( | |
val authenticator: Authenticator | |
) | |
class Authenticator @Inject constructor( | |
val apiService: Lazy<ApiService> | |
) { | |
fun authenticate() { | |
apiService.get().doAuthCall() // Use apiService to authenticate | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HttpClient @Inject constructor( | |
val authenticator: Authenticator | |
) | |
class Authenticator @Inject constructor( | |
val apiService: ApiService | |
) { | |
fun authenticate() { | |
apiService.get().doAuthCall() // Use apiService to authenticate | |
} |
NewerOlder