{"id":350146,"date":"2023-07-12T15:01:29","date_gmt":"2023-07-12T15:01:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=350146"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=350146","title":{"rendered":"<span>\u0420\u0443\u0447\u043d\u043e\u0439 DI \u043d\u0430 \u041a\u043e\u0442\u043b\u0438\u043d\u0435? \u041b\u0435\u0433\u043a\u043e! \u041d\u0443, \u043f\u043e\u0447\u0442\u0438\u2026<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e Dagger &#8212; <s>\u0431\u0438\u0447 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430<\/s> \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u0438\u043d\u0434\u0443\u0441\u0442\u0440\u0438\u0438, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f Dependency Injection. \u0412\u0441\u0435 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e Dagger \u0445\u043e\u0442\u044c \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0449\u043d\u044b\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c, \u043d\u043e \u0441\u0431\u043e\u0440\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441 \u043d\u0438\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, Dagger &#8212; \u0441\u0442\u0440\u0430\u0448\u043d\u044b\u0439 \u0441\u043e\u043d \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445. \u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0435\u0433\u043e? \u041d\u043e \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0447\u0435\u0433\u043e? Koin \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441 \u043b\u043e\u043a\u0430\u0442\u043e\u0440\u044b &#8212; \u0442\u0430\u043a \u0441\u0435\u0431\u0435 \u0438\u0434\u0435\u044f, \u0432\u0435\u0434\u044c \u0432\u0435\u0441\u044c injection \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0438 \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0443\u043f\u0430\u0434\u0435\u0442. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435 \u0440\u0443\u043a\u0430\u043c\u0438?<\/p>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b \u0438 \u0440\u0435\u0448\u0438\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0443\u0447\u043d\u043e\u0439 DI \u0432 \u0441\u0432\u043e\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041c\u043e\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0440\u043e\u043b\u044c \u043b\u0443\u0447\u0448\u0435\u0439 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u0435\u0439. \u041c\u043e\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0441\u043e\u0432\u0435\u0442\u0430\u043c \u0434\u044f\u0434\u044e\u0448\u043a\u0438 \u0411\u043e\u0431\u0430, \u043d\u0435 \u043d\u0430\u0434\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0442\u0438\u043f\u0443 &#171;\u0410 \u043f\u043e\u0447\u0435\u043c\u0443 \u0443 \u0442\u0435\u0431\u044f \u0435\u0441\u0442\u044c <code>WallpaperProvider<\/code>, <code>WallpaperManager<\/code> \u0438 <code>WallpaperRepository<\/code>?&#187;<\/p>\n<p> \u041e\u0434\u043d\u0430\u043a\u043e, \u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0442\u043a\u0440\u044b\u0442 \u043a \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f\u043c \u0438 \u0431\u0443\u0434\u0443 \u0440\u0430\u0434, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0441\u0432\u043e\u0438\u043c\u0438 \u0438\u0434\u0435\u044f\u043c\u0438 \u043f\u043e \u0435\u0451 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044e.<\/p>\n<\/div>\n<\/details>\n<h2>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f 1: \u043e\u0434\u0438\u043d Gradle \u043c\u043e\u0434\u0443\u043b\u044c, \u043e\u0434\u0438\u043d \u0433\u0440\u0430\u0444<\/h2>\n<p>\u041a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0442\u0430\u043a\u043e\u0432\u0430: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c <strong>\u0435\u0434\u0438\u043d\u044b\u0439<\/strong> <strong>\u0433\u0440\u0430\u0444<\/strong> \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041e\u043d \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 application-\u043a\u043b\u0430\u0441\u0441\u0435, \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0433\u0440\u0430\u0444\u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. (\u041f\u043e\u0447\u0442\u0438) \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u0438: \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u043f\u0443\u0442\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 <code>lazy<\/code>. \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u0432 activity(<code>PermissionHandler<\/code>), \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0438\u043c\u0435\u044e\u0442 <code>Noop<\/code>\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u041e\u043d\u0438 \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 <code>Activity<\/code>. \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044d\u0442\u043e \u043d\u0435\u0441\u0435\u0442 \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u0438 \u043c\u0438\u043d\u0443\u0441\u044b: \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u0432\u043e\u0437\u044c\u043c\u0435\u0442 <code>Noop<\/code>\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043e \u0437\u0430\u043c\u0435\u043d\u044b \u043d\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0443\u044e? \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0439 (\u0438 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0439) \u0432\u043e\u043f\u0440\u043e\u0441.<\/p>\n<pre><code class=\"kotlin\">class Graph(private val app: Application) {     val coroutineScope by lazy { CoroutineScope(Dispatchers.IO) }      var permissionHandler: PermissionHandler = PermissionHandler.NoopPermissionHandler     val navController by lazy { createMaterialMotionNavController(app) }     val wallpaperRepository: WallpaperRepository by lazy { WallpaperRepositoryImpl(app, navController) }          \/\/ ... }  class WallManApp: Application() {     val graph by lazy { Graph(this) }     override fun onCreate() {         super.onCreate()         \/\/ ...     } }<\/code><\/pre>\n<p>\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0435\u0437 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 activity. \u0422\u0430\u043a \u0436\u0435 \u043c\u044b \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u0433\u0440\u0430\u0444 \u0447\u0435\u0440\u0435\u0437 <code>CompositionLocal<\/code> \u0432 compose \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"kotlin\">class MainActivity : ComponentActivity() {     private val graph by lazy {         (this.application as WallManApp).graph     }     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         graph.apply {             permissionHandler = AndroidPermissionHandler(this@MainActivity)             \/\/ ...         }                  setContent {             CompositionLocalProvider(LocalGraph provides graph) {                 \/\/ ...             }         }     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u0438? \u041e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e! \u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f extension-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0430\u0434 \u0433\u0440\u0430\u0444\u043e\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u0438. \u042d\u0442\u043e \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0440\u0430\u0437\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0433\u0440\u0430\u0444 \u043e\u0442 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0422\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043b\u0435\u0433\u0447\u0435, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043b\u0435\u0436\u0438\u0442 \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0441 \u0441\u0430\u043c\u043e\u0439 \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u044c\u044e:<\/p>\n<pre><code class=\"kotlin\">fun Graph.MainViewModel() = MainViewModel(wallpapersRepository)  class MainViewModel(     private val repo: WallpapersRepository ) : ViewModel() {   \/\/ ... }<\/code><\/pre>\n<p>\u041e\u0447\u0435\u043d\u044c \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e, \u043f\u0440\u0430\u0432\u0434\u0430? \u0412\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u0438\u0434\u043d\u044b \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u0430 \u0438\u0445 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>\u041a\u0430\u043a \u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u044c \u0432 ui? \u0417\u0434\u0435\u0441\u044c \u0442\u043e\u0436\u0435 \u0432\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u0421\u043e\u0437\u0434\u0430\u0435\u043c <code>Composable<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439:<\/p>\n<pre><code class=\"kotlin\">@Suppress(\"UNCHECKED_CAST\") class ViewModelFactory(val viewModel: () -> ViewModel) : ViewModelProvider.Factory {     override fun &lt;T : ViewModel> create(modelClass: Class&lt;T>): T {         return viewModel() as T     } }  @Composable inline fun &lt;reified T : ViewModel> viewModel(noinline block: @DisallowComposableCalls Graph.() -> T): T {     val graph = LocalGraph.current     return androidx.lifecycle.viewmodel.compose.viewModel(factory = remember { ViewModelFactory { graph.block() } }) } <\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0436\u0435\u0441\u0442\u043a\u0443\u044e \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 ui \u0438 \u0433\u0440\u0430\u0444\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c \u044d\u043a\u0440\u0430\u043d \u043d\u0430 \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: \u0441 \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0438 \u0431\u0435\u0437 \u043d\u0435\u0435. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e MVI \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430:<\/p>\n<pre><code class=\"kotlin\">@Composable fun MainScreen(modifier: Modifier = Modifier) {     val viewModel = viewModel { MainViewModel() }     val state by viewModel.state.collectAsStateWithLifecycle()     MainScreen(state, modifier) }  @Composable private fun MainScreen(   state: MainViewModel.MainScreenState,    modifier: Modifier = Modifier ) {   \/\/ ... }<\/code><\/pre>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u044d\u043a\u0440\u0430\u043d \u0441 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e\u0431 \u043e\u0431\u043e\u044f\u0445, \u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0445\u0435\u0448\u043a\u043e\u0434 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u043e\u0431\u043e\u0438\u043d\u044b \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438. \u0414\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"kotlin\">fun Graph.WallpaperDetailsViewModel(wallpaperHashCode: Int) =     WallpaperDetailsViewModel(wallpaperHashCode, \/* ... *\/)  class WallpaperDetailsViewModel(     private val wallpaperHashCode: Int,     \/\/ ... ) : ViewModel() {     \/\/ ... }  @Composable fun WallpaperDetailsScreen(wallpaperHashCode: Int, modifier: Modifier = Modifier) {     val viewModel = viewModel { WallpaperDetailsViewModel(wallpaperHashCode) }     val state by viewModel.state.collectAsStateWithLifecycle()     WallpaperDetailsScreen(state, modifier) }<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438. \u041f\u0440\u0438 \u0440\u043e\u0441\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432\u0441\u0435 \u0442\u0440\u0443\u0434\u043d\u0435\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d Gradle-\u043c\u043e\u0434\u0443\u043b\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0444\u0438\u0447\u0438 \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 1: <a href=\"https:\/\/gitlab.com\/colorata\/wallman\/-\/tree\/30710046e2be87ffff17fd9d56688cc0d5a72bef\" rel=\"noopener noreferrer nofollow\">gitlab<\/a>.<\/p>\n<h2>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f 2: \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 Gradle \u043c\u043e\u0434\u0443\u043b\u0438, 1 \u0433\u0440\u0430\u0444<\/h2>\n<p>\u0412\u043e\u0442 \u0437\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435. \u0422\u0430\u043a \u043a\u0430\u043a \u0432\u0441\u0435 \u0444\u0438\u0447\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438, \u043c\u044b \u043a\u0430\u043a-\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0438\u0445 \u0432 \u043e\u0434\u0438\u043d \u0433\u0440\u0430\u0444. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0448 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0433\u0440\u0430\u0444 \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e(\u0432 <code>:di:api<\/code> \u0438 <code>:di:impl<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440). \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u0441\u0435 \u0444\u0438\u0447\u0438 \u0434\u0435\u043b\u044f\u0442\u0441\u044f \u043d\u0430 <code>:api<\/code>, <code>:impl<\/code> \u0438 <code>:ui<\/code>(\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e) \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043a\u0430\u043a \u043d\u0430 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f77\/e98\/bbc\/f77e98bbccd2db46240d9038d830cd4e.png\" alt=\"\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438\" title=\"\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438\" width=\"1257\" height=\"657\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f77\/e98\/bbc\/f77e98bbccd2db46240d9038d830cd4e.png\"\/><\/p>\n<div><figcaption>\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0440\u0430\u043d\u0435\u0435, \u0432\u0441\u0435 \u0444\u0438\u0447\u0438 \u0434\u0435\u043b\u044f\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0443\u043b\u0435\u0439:<\/p>\n<ul>\n<li>\n<p><code>:api<\/code> &#8212; \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438 extension-\u0444\u0443\u043d\u0446\u0438\u0438\/\u043f\u0440\u043e\u043f\u0435\u0440\u0442\u0438 \u043a \u044d\u0442\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c(\u0447\u0442\u043e\u0431 \u0436\u0438\u0437\u043d\u044c \u0441\u043b\u0430\u0449\u0435 \u0431\u044b\u043b\u0430)<\/p>\n<\/li>\n<li>\n<p><code>:impl<\/code> &#8212; \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0438\u0437 <code>:api<\/code><\/p>\n<\/li>\n<li>\n<p><code>:ui<\/code> &#8212; \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e, \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0444\u0438\u0447\u0438. \u041c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 <code>:di:api<\/code> \u0434\u043b\u044f \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432\u043e \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u0438. <strong>\u042d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 <\/strong><code>:impl<\/code>!<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c \u0436\u0435 \u0441\u0430\u043c\u044b\u043c.<\/p>\n<p>\u0418 \u0441\u043d\u043e\u0432\u0430 \u043c\u0438\u043d\u0443\u0441\u044b: \u043f\u0440\u0438 \u0440\u043e\u0441\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0433\u0440\u0430\u0444 \u043c\u043e\u0436\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0438\u0441\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u043f\u043e\u0434\u0433\u0440\u0430\u0444\u044b.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 2: <a href=\"https:\/\/gitlab.com\/colorata\/wallman\/-\/tree\/97097053f9d669fe428fc36f370288d8b132b1eb\/\" rel=\"noopener noreferrer nofollow\">gitlab<\/a>.<\/p>\n<h2>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f 3: \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0430 \u043d\u0430 \u043c\u043e\u0434\u0443\u043b\u0438<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0433\u0440\u0430\u0444 \u043d\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0442\u0430\u043a \u0441\u0442\u0440\u0430\u0448\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430 feature-\u043c\u043e\u0434\u0443\u043b\u0438:<\/p>\n<pre><code class=\"kotlin\">interface Graph {     val coreModule: CoreModule     val wallpapersModule: WallpapersModule     \/\/ ... }<\/code><\/pre>\n<p>\u0422\u043e\u0433\u0434\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"kotlin\">interface WallpapersModule: CoreModule {     val wallpapersRepository: WallpapersRepository     \/\/ ... }  class WallpapersModuleImpl(     coreModule: CoreModule,     application: Application ) : WallpapersModule,     CoreModule by coreModule {   \/\/ ... }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043c\u0435\u043d\u044f\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u0433\u0440\u0430\u0444\u0430 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u043e\u0434\u0443\u043b\u044c:<\/p>\n<pre><code class=\"kotlin\">fun WallpapersModule.MainViewModel() = MainViewModel(   wallpapersRepository )  class MainViewModel(     private val repo: WallpapersRepository, ) : ViewModel() {   \/\/ ... }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0444\u0438\u0447\u0443 \u0431\u0435\u0437 \u0432\u0441\u0435\u0433\u043e \u0433\u0440\u0430\u0444\u0430? \u0423\u0431\u0440\u0430\u0442\u044c \u0433\u0440\u0430\u0444 \u0438\u0437 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0444\u0438\u0447\u0438. \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c 2 <s>\u0441\u0442\u0443\u043b\u0430<\/s> \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430.<\/p>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1: \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044f \u0447\u0435\u0440\u0435\u0437 Compose<\/h2>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c <code>CompositionLocal<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0431\u0440\u043e\u0448\u0435\u043d \u0433\u0434\u0435-\u0442\u043e \u0441\u0432\u0435\u0440\u0445\u0443 compose-\u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<p>\u0420\u044f\u0434\u043e\u043c \u0441 <code>WallpapersModule<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 <code>CompositionLocal<\/code>:<\/p>\n<pre><code class=\"kotlin\">interface WallpapersModule: CoreModule {     val wallpapersRepository: WallpapersRepository }  val LocalWallpapersModule =    compositionLocalOf&lt;WallpapersModule> {      error(\"WallpapersModule is not provided\")   }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b <code>CompositionLocals<\/code> \u0432\u0441\u0435\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u043f\u043e\u0434\u0442\u044f\u043d\u0443\u043b\u0438\u0441\u044c, \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u0434\u043b\u044f \u043d\u0438\u0445 \u0432 <code>:di:api<\/code> \u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448\u0435 <code>Activity<\/code>:<\/p>\n<pre><code class=\"kotlin\">@Composable fun ProvideGraphModules(content: @Composable () -> Unit) {     val graph = LocalGraph.current     CompositionLocalProvider(         LocalCoreModule provides graph.coreModule,         LocalWallpapersModule provides graph.wallpapersModule,         \/\/ ...     ) {         content()     } }  class MainActivity : ComponentActivity() {     private val graph by lazy {         (application as WallManApp).graph     }      override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)          setContent {             CompositionLocalProvider(LocalGraph provides graph) {                 ProvideGraphModules {                     \/\/ ...                 }             }         }     } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u044c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043d\u043e\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0432 <code>:my_feature:ui<\/code>:<\/p>\n<pre><code class=\"kotlin\">@Composable inline fun &lt;reified T : ViewModel> viewModel(noinline block: @DisallowComposableCalls WallpapersModule.() -> T): T {     return viewModelWithReceiver(LocalWallpapersModule.current, block) }<\/code><\/pre>\n<p>\u0418 \u0441\u043e\u0437\u0434\u0430\u0442\u044c <code>viewModelWithReceiver<\/code> \u0432 <code>:core:api<\/code>:<\/p>\n<pre><code class=\"kotlin\">@Composable inline fun &lt;reified T : ViewModel, R> viewModelWithReceiver(     receiver: R,     noinline block: @DisallowComposableCalls R.() -> T ): T {     return androidx.lifecycle.viewmodel.compose.viewModel(factory = remember {         ViewModelFactory {             receiver.block()         }     }) }<\/code><\/pre>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0431\u0440\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c <code>:di:api<\/code> \u0438\u0437 <code>:my_feature:ui<\/code>. \u042d\u0442\u043e \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0444\u0438\u0447\u0443 \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0433\u043e \u0433\u0440\u0430\u0444\u0430.<\/p>\n<p>\u041e\u043f\u044f\u0442\u044c \u043c\u0438\u043d\u0443\u0441\u044b: \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043c\u043e\u0434\u0443\u043b\u044c \u0432 <code>ProvideGraphModules<\/code>, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043a\u0440\u0430\u0448\u043d\u0443\u0442\u044c\u0441\u044f. \u041d\u0435 \u043e\u0447\u0435\u043d\u044c \u0431\u043b\u0430\u0433\u043e\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u043f\u043e\u0432\u043e\u0440\u043e\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 1: <a href=\"https:\/\/gitlab.com\/colorata\/wallman\/-\/tree\/8e7e45797d648f1a9fdd8227a03fbceb02372d48\" rel=\"noopener noreferrer nofollow\">gitlab<\/a>.<\/p>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c context receivers<\/h2>\n<p>\u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 <strong>\u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442<\/strong> \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. <\/p>\n<details class=\"spoiler\">\n<summary>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u044d\u0442\u043e\u0442 \u0432\u0430\u0448 context receivers?<\/summary>\n<div class=\"spoiler__content\">\n<p>Context receivers \u043c\u043d\u043e\u0433\u0438\u043c \u043f\u043e\u0445\u043e\u0436\u0438 extension-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0438\u043c\u0435\u044e\u0442 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u044b\u0435 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f. \u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445:<\/p>\n<pre><code class=\"kotlin\">fun Logger.allLogsByTag(tag: String): List&lt;String> {     return allLogs().filter { it.tag == tag } }  context(Logger) fun Storage.storeAppState() {     log(\"Storage\", \"Starting storing...\")     val logs = allLogsByTag(\"tag\")     \/\/ ... }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>allLogsByTag<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <strong>\u043d\u0430\u0434 <\/strong><code>Logger<\/code>, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a <code>storeAppState<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043a\u043e\u0443\u043f\u0435, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c Logger.<\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 <a href=\"https:\/\/kotlinlang.org\/docs\/whatsnew1620.html#prototype-of-context-receivers-for-kotlin-jvm\" rel=\"noopener noreferrer nofollow\">\u0441\u0430\u0439\u0442\u0435 Jetbrains<\/a><\/p>\n<\/div>\n<\/details>\n<p>\u041d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u044e context receivers \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 <strong>prototype<\/strong>. \u041f\u043e\u043a\u0430 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0430 Kotlin\/JVM, \u0430 Jetbrains <strong>\u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e\u0442<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435:<\/p>\n<blockquote>\n<p>The feature is a prototype available only for Kotlin\/JVM. With <code>-Xcontext-receivers<\/code><br \/> enabled, the compiler will produce pre-release binaries that cannot be<br \/> used in production code. Use context receivers only in your toy<br \/> projects. We appreciate your feedback in <a href=\"https:\/\/youtrack.jetbrains.com\/issues\/KT\" rel=\"noopener noreferrer nofollow\">YouTrack<\/a>.<\/p>\n<\/blockquote>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043a context receivers, \u0442\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0444\u043b\u0430\u0433 \u0432 build.gradle.kts:<\/p>\n<pre><code class=\"kotlin\">tasks.withType(KotlinCompile::class.java) {     kotlinOptions.freeCompilerArgs += listOf(\"-Xcontext-receivers\") }<\/code><\/pre>\n<p>\u0423\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0437 composable-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0433\u0440\u0430\u0444\u0430:<\/p>\n<pre><code class=\"kotlin\">@Composable inline fun &lt;reified T : ViewModel> viewModel(noinline block: @DisallowComposableCalls () -> T): T {     return androidx.lifecycle.viewmodel.compose.viewModel(factory = remember {         ViewModelFactory {             block()         }     }) }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u0438 \u0432 ui:<\/p>\n<pre><code class=\"kotlin\">context(WallpapersModule) @Composable fun WallpaperDetailsScreen(wallpaperHashCode: Int, modifier: Modifier = Modifier) {     val viewModel = viewModel { WallpaperDetailsViewModel(wallpaperHashCode) }     val state by viewModel.state.collectAsStateWithLifecycle()     WallpaperDetailsScreen(state, modifier) }<\/code><\/pre>\n<p>\u0412 \u043c\u0435\u0441\u0442\u0435 \u0432\u044b\u0437\u043e\u0432\u0430(\u0432 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440) \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0431\u043b\u043e\u043a <code>with<\/code> \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430:<\/p>\n<pre><code class=\"kotlin\">with(graph.wallpapersModule) {     composable(\"WallpaperDetails\/{hashcode}\") {         val hashCode = ...         WallpaperDetailsScreen(hashCode)     }     \/\/ ... }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c context receivers &#8212; \u0435\u0449\u0435 \u043e\u0434\u0438\u043d (\u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e) \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0430 \u043c\u043e\u0434\u0443\u043b\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u043c\u0438, \u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u0432\u044b\u0434\u0430\u043b compose \u043e\u0431 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code>restartable scheme(\"[androidx.compose.ui.UiComposable]\") fun WallpaperDetailsScreen(   unstable _context_receiver_0: WallpapersModule   stable wallpaperHashCode: Int   stable modifier: Modifier? = @static Companion ) restartable skippable scheme(\"[androidx.compose.ui.UiComposable]\") fun WallpaperDetailsScreen(   stable state: WallpaperDetailsScreenState   stable modifier: Modifier? = @static Companion )<\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c, \u0447\u0442\u043e composable-\u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0430\u044f context receivers, non-skippable. \u041a\u0440\u0438\u0442\u0438\u0447\u043d\u043e \u043b\u0438 \u044d\u0442\u043e? \u041d\u0435\u0442, \u0432\u0435\u0434\u044c composable-\u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0430\u044f state &#8212; skippable. \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438 \u043e\u0431\u0445\u043e\u0434\u0435 \u0434\u0435\u0440\u0435\u0432\u0430 compose \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043e \u0441\u0442\u0435\u0439\u0442\u043e\u043c &#8212; \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e compose-\u043a\u043e\u0434\u0430: <a href=\"https:\/\/habr.com\/p\/742854\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u044f \u043e\u0442 Ozon Tech<\/a>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0410 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043a\u0430\u043a?<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0425\u043e\u0440\u043e\u0448\u0438\u0439 \u0432\u043e\u043f\u0440\u043e\u0441. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044f \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u0440\u0430\u0437\u043d\u0438\u0446\u044b, \u0434\u0430 \u0438 layout inspector \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0445 \u0440\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0439.<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u0437 \u043c\u0438\u043d\u0443\u0441\u043e\u0432: context receivers \u043f\u043e\u043a\u0430 <strong>\u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b<\/strong>(\u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0430 K2 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430) \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 JVM (\u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 IOS  \u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430). \u0415\u0441\u043b\u0438 Jetbrains \u0440\u0435\u0448\u0438\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u044b\u0437\u043e\u0432\u0430, \u0442\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u0434 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f. <\/p>\n<p>\u041a\u0430\u043a <s>\u043a\u043e\u0441\u0442\u044b\u043b\u044c<\/s> \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 &#8212; \u0441\u0430\u043c\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"kotlin\">context(WallpapersModule) @Composable fun WallpaperDetailsScreen(wallpaperHashCode: Int, modifier: Modifier = Modifier) {     \/\/ ... }<\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0430:<\/p>\n<pre><code class=\"kotlin\">@Composable fun WallpaperDetailsScreen(   module: WallpapersModule,    wallpaperHashCode: Int,    modifier: Modifier = Modifier ) {     \/\/ ... }<\/code><\/pre>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 2: <a href=\"https:\/\/gitlab.com\/colorata\/wallman\/-\/tree\/082eb7cacc8df5e7364f4127d32ee0da781ca62f\" rel=\"noopener noreferrer nofollow\">gitlab<\/a>.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c, \u043f\u043e-\u043c\u043e\u0435\u043c\u0443, \u0437\u0434\u0435\u0441\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f context receivers, \u043e\u043d\u0438 \u0434\u0430\u044e\u0442 <strong>\u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044e<\/strong> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>\u0427\u0442\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043e\u0442 \u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u0420\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0423\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 Dagger<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u0430 \u0432 IDE \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 (\u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 feedback loop)<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 Dagger<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u043e \u043c\u0438\u043d\u0443\u0441\u044b \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c:<\/p>\n<ul>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code>CompositionLocal<\/code><\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430 context receivers \u043d\u0430 IOS \u0438 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u0431\u0435\u0437 \u043a\u043e\u0441\u0442\u044b\u043b\u0435\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u041b\u0435\u0433\u043a\u043e \u043b\u0438 \u0431\u044b\u043b\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0443\u0447\u043d\u043e\u0439 DI? \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u0410 \u0431\u044b\u043b\u043e \u043b\u0438 \u043d\u0443\u0436\u043d\u043e? \u042f \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u0432\u0430\u0441.<\/p>\n<p>\u0421\u043e\u0432\u0435\u0442\u0443\u044e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0440\u0443\u0447\u043d\u043e\u0433\u043e DI:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=Guh3gQO4mFE\" rel=\"noopener noreferrer nofollow\">Youtube<\/a><\/p>\n<\/li>\n<li>\n<p>\u0421\u0442\u0430\u0442\u044c\u0438: <a href=\"https:\/\/mishkun.xyz\/blog\/Di-frameworks.html\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0437<\/a>, <a href=\"https:\/\/mishkun.xyz\/blog\/Manual-DI-Cookbook.html\" rel=\"noopener noreferrer nofollow\">\u0434\u0432\u0430<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 &#8212; \u0440\u0435\u0448\u0430\u0442\u044c \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0430\u043c. <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/746978\/\"> https:\/\/habr.com\/ru\/articles\/746978\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e Dagger &#8212; <s>\u0431\u0438\u0447 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430<\/s> \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u0438\u043d\u0434\u0443\u0441\u0442\u0440\u0438\u0438, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f Dependency Injection. \u0412\u0441\u0435 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e Dagger \u0445\u043e\u0442\u044c \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0449\u043d\u044b\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c, \u043d\u043e \u0441\u0431\u043e\u0440\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441 \u043d\u0438\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, Dagger &#8212; \u0441\u0442\u0440\u0430\u0448\u043d\u044b\u0439 \u0441\u043e\u043d \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445. \u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0435\u0433\u043e? \u041d\u043e \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0447\u0435\u0433\u043e? Koin \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441 \u043b\u043e\u043a\u0430\u0442\u043e\u0440\u044b &#8212; \u0442\u0430\u043a \u0441\u0435\u0431\u0435 \u0438\u0434\u0435\u044f, \u0432\u0435\u0434\u044c \u0432\u0435\u0441\u044c injection \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0438 \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0443\u043f\u0430\u0434\u0435\u0442. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435 \u0440\u0443\u043a\u0430\u043c\u0438?<\/p>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b \u0438 \u0440\u0435\u0448\u0438\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0443\u0447\u043d\u043e\u0439 DI \u0432 \u0441\u0432\u043e\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041c\u043e\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0440\u043e\u043b\u044c \u043b\u0443\u0447\u0448\u0435\u0439 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u0435\u0439. \u041c\u043e\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0441\u043e\u0432\u0435\u0442\u0430\u043c \u0434\u044f\u0434\u044e\u0448\u043a\u0438 \u0411\u043e\u0431\u0430, \u043d\u0435 \u043d\u0430\u0434\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0442\u0438\u043f\u0443 &#171;\u0410 \u043f\u043e\u0447\u0435\u043c\u0443 \u0443 \u0442\u0435\u0431\u044f \u0435\u0441\u0442\u044c <code>WallpaperProvider<\/code>, <code>WallpaperManager<\/code> \u0438 <code>WallpaperRepository<\/code>?&#187;<\/p>\n<p> \u041e\u0434\u043d\u0430\u043a\u043e, \u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0442\u043a\u0440\u044b\u0442 \u043a \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f\u043c \u0438 \u0431\u0443\u0434\u0443 \u0440\u0430\u0434, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0441\u0432\u043e\u0438\u043c\u0438 \u0438\u0434\u0435\u044f\u043c\u0438 \u043f\u043e \u0435\u0451 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044e.<\/p>\n<\/div>\n<\/details>\n<h2>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f 1: \u043e\u0434\u0438\u043d Gradle \u043c\u043e\u0434\u0443\u043b\u044c, \u043e\u0434\u0438\u043d \u0433\u0440\u0430\u0444<\/h2>\n<p>\u041a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0442\u0430\u043a\u043e\u0432\u0430: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c <strong>\u0435\u0434\u0438\u043d\u044b\u0439<\/strong> <strong>\u0433\u0440\u0430\u0444<\/strong> \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041e\u043d \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 application-\u043a\u043b\u0430\u0441\u0441\u0435, \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0433\u0440\u0430\u0444\u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. (\u041f\u043e\u0447\u0442\u0438) \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u0438: \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u043f\u0443\u0442\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 <code>lazy<\/code>. \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u0432 activity(<code>PermissionHandler<\/code>), \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0438\u043c\u0435\u044e\u0442 <code>Noop<\/code>\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u041e\u043d\u0438 \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 <code>Activity<\/code>. \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044d\u0442\u043e \u043d\u0435\u0441\u0435\u0442 \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u0438 \u043c\u0438\u043d\u0443\u0441\u044b: \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u0432\u043e\u0437\u044c\u043c\u0435\u0442 <code>Noop<\/code>\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043e \u0437\u0430\u043c\u0435\u043d\u044b \u043d\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0443\u044e? \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0439 (\u0438 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0439) \u0432\u043e\u043f\u0440\u043e\u0441.<\/p>\n<pre><code class=\"kotlin\">class Graph(private val app: Application) {     val coroutineScope by lazy { CoroutineScope(Dispatchers.IO) }      var permissionHandler: PermissionHandler = PermissionHandler.NoopPermissionHandler     val navController by lazy { createMaterialMotionNavController(app) }     val wallpaperRepository: WallpaperRepository by lazy { WallpaperRepositoryImpl(app, navController) }          \/\/ ... }  class WallManApp: Application() {     val graph by lazy { Graph(this) }     override fun onCreate() {         super.onCreate()         \/\/ ...     } }<\/code><\/pre>\n<p>\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0435\u0437 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 activity. \u0422\u0430\u043a \u0436\u0435 \u043c\u044b \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u0433\u0440\u0430\u0444 \u0447\u0435\u0440\u0435\u0437 <code>CompositionLocal<\/code> \u0432 compose \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"kotlin\">class MainActivity : ComponentActivity() {     private val graph by lazy {         (this.application as WallManApp).graph     }     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         graph.apply {             permissionHandler = AndroidPermissionHandler(this@MainActivity)             \/\/ ...         }                  setContent {             CompositionLocalProvider(LocalGraph provides graph) {                 \/\/ ...             }         }     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u0438? \u041e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e! \u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f extension-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0430\u0434 \u0433\u0440\u0430\u0444\u043e\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u0438. \u042d\u0442\u043e \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0440\u0430\u0437\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0433\u0440\u0430\u0444 \u043e\u0442 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0422\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043b\u0435\u0433\u0447\u0435, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043b\u0435\u0436\u0438\u0442 \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0441 \u0441\u0430\u043c\u043e\u0439 \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u044c\u044e:<\/p>\n<pre><code class=\"kotlin\">fun Graph.MainViewModel() = MainViewModel(wallpapersRepository)  class MainViewModel(     private val repo: WallpapersRepository ) : ViewModel() {   \/\/ ... }<\/code><\/pre>\n<p>\u041e\u0447\u0435\u043d\u044c \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e, \u043f\u0440\u0430\u0432\u0434\u0430? \u0412\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u0438\u0434\u043d\u044b \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u0430 \u0438\u0445 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>\u041a\u0430\u043a \u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u044c \u0432 ui? \u0417\u0434\u0435\u0441\u044c \u0442\u043e\u0436\u0435 \u0432\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u0421\u043e\u0437\u0434\u0430\u0435\u043c <code>Composable<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439:<\/p>\n<pre><code class=\"kotlin\">@Suppress(\"UNCHECKED_CAST\") class ViewModelFactory(val viewModel: () -> ViewModel) : ViewModelProvider.Factory {     override fun &lt;T : ViewModel> create(modelClass: Class&lt;T>): T {         return viewModel() as T     } }  @Composable inline fun &lt;reified T : ViewModel> viewModel(noinline block: @DisallowComposableCalls Graph.() -> T): T {     val graph = LocalGraph.current     return androidx.lifecycle.viewmodel.compose.viewModel(factory = remember { ViewModelFactory { graph.block() } }) } <\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0436\u0435\u0441\u0442\u043a\u0443\u044e \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 ui \u0438 \u0433\u0440\u0430\u0444\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c \u044d\u043a\u0440\u0430\u043d \u043d\u0430 \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: \u0441 \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0438 \u0431\u0435\u0437 \u043d\u0435\u0435. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e MVI \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430:<\/p>\n<pre><code class=\"kotlin\">@Composable fun MainScreen(modifier: Modifier = Modifier) {     val viewModel = viewModel { MainViewModel() }     val state by viewModel.state.collectAsStateWithLifecycle()     MainScreen(state, modifier) }  @Composable private fun MainScreen(   state: MainViewModel.MainScreenState,    modifier: Modifier = Modifier ) {   \/\/ ... }<\/code><\/pre>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u044d\u043a\u0440\u0430\u043d \u0441 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e\u0431 \u043e\u0431\u043e\u044f\u0445, \u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0445\u0435\u0448\u043a\u043e\u0434 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u043e\u0431\u043e\u0438\u043d\u044b \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438. \u0414\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"kotlin\">fun Graph.WallpaperDetailsViewModel(wallpaperHashCode: Int) =     WallpaperDetailsViewModel(wallpaperHashCode, \/* ... *\/)  class WallpaperDetailsViewModel(     private val wallpaperHashCode: Int,     \/\/ ... ) : ViewModel() {     \/\/ ... }  @Composable fun WallpaperDetailsScreen(wallpaperHashCode: Int, modifier: Modifier = Modifier) {     val viewModel = viewModel { WallpaperDetailsViewModel(wallpaperHashCode) }     val state by viewModel.state.collectAsStateWithLifecycle()     WallpaperDetailsScreen(state, modifier) }<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438. \u041f\u0440\u0438 \u0440\u043e\u0441\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432\u0441\u0435 \u0442\u0440\u0443\u0434\u043d\u0435\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d Gradle-\u043c\u043e\u0434\u0443\u043b\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0444\u0438\u0447\u0438 \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 1: <a href=\"https:\/\/gitlab.com\/colorata\/wallman\/-\/tree\/30710046e2be87ffff17fd9d56688cc0d5a72bef\" rel=\"noopener noreferrer nofollow\">gitlab<\/a>.<\/p>\n<h2>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f 2: \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 Gradle \u043c\u043e\u0434\u0443\u043b\u0438, 1 \u0433\u0440\u0430\u0444<\/h2>\n<p>\u0412\u043e\u0442 \u0437\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435. \u0422\u0430\u043a \u043a\u0430\u043a \u0432\u0441\u0435 \u0444\u0438\u0447\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438, \u043c\u044b \u043a\u0430\u043a-\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0438\u0445 \u0432 \u043e\u0434\u0438\u043d \u0433\u0440\u0430\u0444. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0448 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0433\u0440\u0430\u0444 \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e(\u0432 <code>:di:api<\/code> \u0438 <code>:di:impl<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440). \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u0441\u0435 \u0444\u0438\u0447\u0438 \u0434\u0435\u043b\u044f\u0442\u0441\u044f \u043d\u0430 <code>:api<\/code>, <code>:impl<\/code> \u0438 <code>:ui<\/code>(\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e) \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043a\u0430\u043a \u043d\u0430 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0440\u0430\u043d\u0435\u0435, \u0432\u0441\u0435 \u0444\u0438\u0447\u0438 \u0434\u0435\u043b\u044f\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0443\u043b\u0435\u0439:<\/p>\n<ul>\n<li>\n<p><code>:api<\/code> &#8212; \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438 extension-\u0444\u0443\u043d\u0446\u0438\u0438\/\u043f\u0440\u043e\u043f\u0435\u0440\u0442\u0438 \u043a \u044d\u0442\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c(\u0447\u0442\u043e\u0431 \u0436\u0438\u0437\u043d\u044c \u0441\u043b\u0430\u0449\u0435 \u0431\u044b\u043b\u0430)<\/p>\n<\/li>\n<li>\n<p><code>:impl<\/code> &#8212; \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0438\u0437 <code>:api<\/code><\/p>\n<\/li>\n<li>\n<p><code>:ui<\/code> &#8212; \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e, \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0444\u0438\u0447\u0438. \u041c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 <code>:di:api<\/code> \u0434\u043b\u044f \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432\u043e \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u0438. <strong>\u042d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 <\/strong><code>:impl<\/code>!<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c \u0436\u0435 \u0441\u0430\u043c\u044b\u043c.<\/p>\n<p>\u0418 \u0441\u043d\u043e\u0432\u0430 \u043c\u0438\u043d\u0443\u0441\u044b: \u043f\u0440\u0438 \u0440\u043e\u0441\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0433\u0440\u0430\u0444 \u043c\u043e\u0436\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0438\u0441\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u043f\u043e\u0434\u0433\u0440\u0430\u0444\u044b.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 2: <a href=\"https:\/\/gitlab.com\/colorata\/wallman\/-\/tree\/97097053f9d669fe428fc36f370288d8b132b1eb\/\" rel=\"noopener noreferrer nofollow\">gitlab<\/a>.<\/p>\n<h2>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f 3: \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0430 \u043d\u0430 \u043c\u043e\u0434\u0443\u043b\u0438<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0433\u0440\u0430\u0444 \u043d\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0442\u0430\u043a \u0441\u0442\u0440\u0430\u0448\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430 feature-\u043c\u043e\u0434\u0443\u043b\u0438:<\/p>\n<pre><code class=\"kotlin\">interface Graph {     val coreModule: CoreModule     val wallpapersModule: WallpapersModule     \/\/ ... }<\/code><\/pre>\n<p>\u0422\u043e\u0433\u0434\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"kotlin\">interface WallpapersModule: CoreModule {     val wallpapersRepository: WallpapersRepository     \/\/ ... }  class WallpapersModuleImpl(     coreModule: CoreModule,     application: Application ) : WallpapersModule,     CoreModule by coreModule {   \/\/ ... }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043c\u0435\u043d\u044f\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u0433\u0440\u0430\u0444\u0430 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u043e\u0434\u0443\u043b\u044c:<\/p>\n<pre><code class=\"kotlin\">fun WallpapersModule.MainViewModel() = MainViewModel(   wallpapersRepository )  class MainViewModel(     private val repo: WallpapersRepository, ) : ViewModel() {   \/\/ ... }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0444\u0438\u0447\u0443 \u0431\u0435\u0437 \u0432\u0441\u0435\u0433\u043e \u0433\u0440\u0430\u0444\u0430? \u0423\u0431\u0440\u0430\u0442\u044c \u0433\u0440\u0430\u0444 \u0438\u0437 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0444\u0438\u0447\u0438. \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c 2 <s>\u0441\u0442\u0443\u043b\u0430<\/s> \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430.<\/p>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1: \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044f \u0447\u0435\u0440\u0435\u0437 Compose<\/h2>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c <code>CompositionLocal<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0431\u0440\u043e\u0448\u0435\u043d \u0433\u0434\u0435-\u0442\u043e \u0441\u0432\u0435\u0440\u0445\u0443 compose-\u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<p>\u0420\u044f\u0434\u043e\u043c \u0441 <code>WallpapersModule<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 <code>CompositionLocal<\/code>:<\/p>\n<pre><code class=\"kotlin\">interface WallpapersModule: CoreModule {     val wallpapersRepository: WallpapersRepository }  val LocalWallpapersModule =    compositionLocalOf&lt;WallpapersModule> {      error(\"WallpapersModule is not provided\")   }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b <code>CompositionLocals<\/code> \u0432\u0441\u0435\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u043f\u043e\u0434\u0442\u044f\u043d\u0443\u043b\u0438\u0441\u044c, \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u0434\u043b\u044f \u043d\u0438\u0445 \u0432 <code>:di:api<\/code> \u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448\u0435 <code>Activity<\/code>:<\/p>\n<pre><code class=\"kotlin\">@Composable fun ProvideGraphModules(content: @Composable () -> Unit) {     val graph = LocalGraph.current     CompositionLocalProvider(         LocalCoreModule provides graph.coreModule,         LocalWallpapersModule provides graph.wallpapersModule,         \/\/ ...     ) {         content()     } }  class MainActivity : ComponentActivity() {     private val graph by lazy {         (application as WallManApp).graph     }      override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)          setContent {             CompositionLocalProvider(LocalGraph provides graph) {                 ProvideGraphModules {                     \/\/ ...                 }             }         }     } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u044c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043d\u043e\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0432 <code>:my_feature:ui<\/code>:<\/p>\n<pre><code class=\"kotlin\">@Composable inline fun &lt;reified T : ViewModel> viewModel(noinline block: @DisallowComposableCalls WallpapersModule.() -> T): T {     return viewModelWithReceiver(LocalWallpapersModule.current, block) }<\/code><\/pre>\n<p>\u0418 \u0441\u043e\u0437\u0434\u0430\u0442\u044c <code>viewModelWithReceiver<\/code> \u0432 <code>:core:api<\/code>:<\/p>\n<pre><code class=\"kotlin\">@Composable inline fun &lt;reified T : ViewModel, R> viewModelWithReceiver(     receiver: R,     noinline block: @DisallowComposableCalls R.() -> T ): T {     return androidx.lifecycle.viewmodel.compose.viewModel(factory = remember {         ViewModelFactory {             receiver.block()         }     }) }<\/code><\/pre>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0431\u0440\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c <code>:di:api<\/code> \u0438\u0437 <code>:my_feature:ui<\/code>. \u042d\u0442\u043e \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0444\u0438\u0447\u0443 \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0433\u043e \u0433\u0440\u0430\u0444\u0430.<\/p>\n<p>\u041e\u043f\u044f\u0442\u044c \u043c\u0438\u043d\u0443\u0441\u044b: \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043c\u043e\u0434\u0443\u043b\u044c \u0432 <code>ProvideGraphModules<\/code>, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043a\u0440\u0430\u0448\u043d\u0443\u0442\u044c\u0441\u044f. \u041d\u0435 \u043e\u0447\u0435\u043d\u044c \u0431\u043b\u0430\u0433\u043e\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u043f\u043e\u0432\u043e\u0440\u043e\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 1: <a href=\"https:\/\/gitlab.com\/colorata\/wallman\/-\/tree\/8e7e45797d648f1a9fdd8227a03fbceb02372d48\" rel=\"noopener noreferrer nofollow\">gitlab<\/a>.<\/p>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c context receivers<\/h2>\n<p>\u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 <strong>\u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442<\/strong> \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. <\/p>\n<details class=\"spoiler\">\n<summary>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u044d\u0442\u043e\u0442 \u0432\u0430\u0448 context receivers?<\/summary>\n<div class=\"spoiler__content\">\n<p>Context receivers \u043c\u043d\u043e\u0433\u0438\u043c \u043f\u043e\u0445\u043e\u0436\u0438 extension-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0438\u043c\u0435\u044e\u0442 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u044b\u0435 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f. \u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445:<\/p>\n<pre><code class=\"kotlin\">fun Logger.allLogsByTag(tag: String): List&lt;String> {     return allLogs().filter { it.tag == tag } }  context(Logger) fun Storage.storeAppState() {     log(\"Storage\", \"Starting storing...\")     val logs = allLogsByTag(\"tag\")     \/\/ ... }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>allLogsByTag<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <strong>\u043d\u0430\u0434 <\/strong><code>Logger<\/code>, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a <code>storeAppState<\/code> \u043c\u043e\u0436\u0435\u0442<\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-350146","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/350146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=350146"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/350146\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=350146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=350146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=350146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}