Created
July 5, 2020 21:54
-
-
Save Garyfimo/56d348035df3dc4459ba142635522e4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 AppServiceLocator : ServiceLocator { | |
private val calculadorUseCase: CalculadorUseCase by lazy { | |
CalculadorUseCaseImpl() | |
} | |
private val evaluadorUseCase: EvaluadorUseCase by lazy { | |
EvaluadorUseCaseImpl(validadorUseCase, evaluadorExpresionUseCase) | |
} | |
private val evaluadorExpresionUseCase: EvaluadorExpresionUseCase by lazy { | |
EvaluadorExpresionUseCaseImpl(calculadorUseCase) | |
} | |
private val validadorUseCase: ValidadorUseCase by lazy { | |
ValidadorUseCaseImpl() | |
} | |
override val mainViewModelFactory: MainViewModelFactory by lazy { | |
MainViewModelFactory(evaluadorUseCase) | |
} | |
} |
This file contains hidden or 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 CalculadoraApplication : Application() , ServiceLocatorProvider { | |
override val serviceLocator: ServiceLocator by lazy { AppServiceLocator() } | |
} |
This file contains hidden or 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
interface ServiceLocator { | |
val mainViewModelFactory : MainViewModelFactory | |
} |
This file contains hidden or 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
interface ServiceLocatorActivity : ServiceLocatorProvider { | |
val self: Activity | |
override val serviceLocator: ServiceLocator | |
get() = (self.application as? ServiceLocatorProvider)?.serviceLocator | |
?: throw IllegalStateException("Application must implement ServiceLocatorProvider in order to provide global service locator, or implement this property to provide your own ServiceLocator") | |
} |
This file contains hidden or 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
interface ServiceLocatorProvider { | |
val serviceLocator: ServiceLocator | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment