{ val service = WeatherService() val formatter = WeatherFormatter() val forecast = service.getForecast(location) println(formatter.format(forecast)) } }
{ val service = WeatherService() val formatter = WeatherFormatter() val forecast = service.getForecast(location) println(formatter.format(forecast)) } }
WeatherService, private val formatter: WeatherFormatter ) { lateinit var printer: WeatherPrinter /// ..... } fun main() { val service = WeatherService() val formatter = WeatherFormatter() val app = WeatherApp(service, formatter) app.printer = WeatherPrinter() }
WeatherService, private val formatter: WeatherFormatter ) { lateinit var printer: WeatherPrinter /// ..... } fun main() { val service = WeatherService() val formatter = WeatherFormatter() val app = WeatherApp(service, formatter) app.printer = WeatherPrinter() }
WeatherService, private val formatter: WeatherFormatter ) { lateinit var printer: WeatherPrinter /// ..... } fun main() { val service = WeatherService() val formatter = WeatherFormatter() val app = WeatherApp(service, formatter) app.printer = WeatherPrinter() }
WeatherService, private val formatter: WeatherFormatter ) { lateinit var printer: WeatherPrinter /// ..... } fun main() { val service = WeatherService() val formatter = WeatherFormatter() val app = WeatherApp(service, formatter) app.printer = WeatherPrinter() }
by viewModels<ActivityRetainedViewModel> { object : ViewModelProvider.Factory { override fun <T : ViewModel> create(modelClass: Class<T>): T { val app = applicationContext as WeatherApplication val graph = (app.graph as WeatherActivityRetainedGraph.Factory) .createWeatherActivityRetainedGraph() @Suppress("UNCHECKED_CAST") return ActivityRetainedViewModel(graph) as T } } } } class ActivityRetainedViewModel(val graph: WeatherActivityRetainedGraph) : ViewModel()
by viewModels<ActivityRetainedViewModel> { object : ViewModelProvider.Factory { override fun <T : ViewModel> create(modelClass: Class<T>): T { val app = applicationContext as WeatherApplication val graph = (app.graph as WeatherActivityRetainedGraph.Factory) .createWeatherActivityRetainedGraph() @Suppress("UNCHECKED_CAST") return ActivityRetainedViewModel(graph) as T } } } } class ActivityRetainedViewModel(val graph: WeatherActivityRetainedGraph) : ViewModel()
by viewModels<ActivityRetainedViewModel> { object : ViewModelProvider.Factory { override fun <T : ViewModel> create(modelClass: Class<T>): T { val app = applicationContext as WeatherApplication val graph = (app.graph as WeatherActivityRetainedGraph.Factory) .createWeatherActivityRetainedGraph() @Suppress("UNCHECKED_CAST") return ActivityRetainedViewModel(graph) as T } } } } class ActivityRetainedViewModel(val graph: WeatherActivityRetainedGraph) : ViewModel()
by viewModels<ActivityRetainedViewModel> { object : ViewModelProvider.Factory { override fun <T : ViewModel> create(modelClass: Class<T>): T { val app = applicationContext as WeatherApplication val graph = (app.graph as WeatherActivityRetainedGraph.Factory) .createWeatherActivityRetainedGraph() @Suppress("UNCHECKED_CAST") return ActivityRetainedViewModel(graph) as T } } } } class ActivityRetainedViewModel(val graph: WeatherActivityRetainedGraph) : ViewModel()
by viewModels<ActivityRetainedViewModel> { object : ViewModelProvider.Factory { override fun <T : ViewModel> create(modelClass: Class<T>): T { val app = applicationContext as WeatherApplication val graph = (app.graph as WeatherActivityRetainedGraph.Factory) .createWeatherActivityRetainedGraph() @Suppress("UNCHECKED_CAST") return ActivityRetainedViewModel(graph) as T } } } } class ActivityRetainedViewModel(val graph: WeatherActivityRetainedGraph) : ViewModel()
= compositionLocalOf<ViewGraph> { error("ViewGraph not set") } @ContributesTo(ViewScoped::class) interface WeatherContribution { val formatter: WeatherFormatter } not a Module / BindingContainer
= compositionLocalOf<ViewGraph> { error("ViewGraph not set") } @ContributesTo(ViewScoped::class) interface WeatherContribution { val formatter: WeatherFormatter } @Composable inline fun <reified T> contribution(): T { return LocalViewGraph.current as T }
= compositionLocalOf<ViewGraph> { error("ViewGraph not set") } @ContributesTo(ViewScoped::class) interface WeatherContribution { val formatter: WeatherFormatter } @Composable inline fun <reified T> contribution(): T { return LocalViewGraph.current as T } @Composable fun WeatherScreen() { val contribution = contribution<WeatherContribution>() val formatter = remember { contribution.formatter } }
= compositionLocalOf<ViewGraph> { error("ViewGraph not set") } @ContributesTo(ViewScoped::class) interface WeatherContribution { val formatter: WeatherFormatter } @Composable inline fun <reified T> contribution(): T { return LocalViewGraph.current as T } @Composable fun WeatherScreen() { val contribution = LocalViewGraph.current.asContribution<WeatherContribution>() val formatter = remember { contribution.formatter } }