{"id":356947,"date":"2024-05-20T23:40:24","date_gmt":"2024-05-20T23:40:24","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=356947"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-20T23:40:24","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=356947","title":{"rendered":"<span>Kodein DI \u0434\u043b\u044f Android. KMP \u0438 Compose<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7a2\/1d5\/b44\/7a21d5b44329d4343451eda89ccc2101.png\" width=\"1120\" height=\"630\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7a2\/1d5\/b44\/7a21d5b44329d4343451eda89ccc2101.png\"\/><\/figure>\n<p>\u0411\u044b\u0442\u044c \u0432 \u0430\u0432\u0430\u043d\u0433\u0430\u0440\u0434\u0435 \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u2014 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u0430\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u043e\u0433\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u0443\u0436\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u044f\u0442 \u043d\u0430 Jetpack Compose, \u0430 \u0441\u0430\u043c\u044b\u0435 \u0441\u043c\u0435\u043b\u044b\u0435 \u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0434\u0430\u0436\u0435 \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 KMP. \u041c\u044b \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0414\u0440\u0438\u043d\u043a\u0438\u0442 \u0442\u043e\u0436\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 Jetpack Compose (\u0441 KMP \u043f\u043e\u043a\u0430 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434).<\/p>\n<p>\u041d\u0443 \u0438 \u043a\u0430\u043a \u0436\u0435 \u0436\u0438\u0442\u044c \u0441\u043e \u0432\u0441\u0435\u043c \u044d\u0442\u0438\u043c \u0431\u0435\u0437 DI? \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043d\u0438\u043a\u0430\u043a. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c DI Kodein \u0432 Kotlin Multiplatform \u0438 Jetpack Compose.<\/p>\n<p>\u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0438\u0437 \u0446\u0438\u043a\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u043f\u0440\u043e Kodein DI \u0434\u043b\u044f Android:<\/p>\n<p>\u0427\u0430\u0441\u0442\u044c 1: <a href=\"https:\/\/habr.com\/ru\/companies\/dododev\/articles\/755288\/\">Kodein DI \u0434\u043b\u044f Android. \u041e\u0441\u043d\u043e\u0432\u044b API <\/a><\/p>\n<p>\u0427\u0430\u0441\u0442\u044c 2: Kodein DI \u0434\u043b\u044f Android. KMP \u0438 Compose<\/p>\n<p>\u041f\u043e\u0433\u043d\u0430\u043b\u0438.<\/p>\n<h2>Kotlin Multiplatform<\/h2>\n<p><a href=\"https:\/\/kotlinlang.org\/docs\/multiplatform.html\">Kotlin Multiplatform<\/a> \u0432\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0448\u0443 \u0436\u0438\u0437\u043d\u044c, \u0432\u044b\u0431\u0438\u0432\u0430\u044f \u0434\u0432\u0435\u0440\u044c \u043d\u043e\u0433\u043e\u0439. \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439 \u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0432\u043d\u0435\u0434\u0440\u0438\u043b\u0438 \u0441\u0435\u0431\u0435 KMP \u2014 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043d\u043e, \u0441\u0443\u0434\u044f \u043f\u043e \u0442\u0435\u043c\u0430\u043c \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u043b\u0435\u0442, \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u0435, \u0431\u0443\u0434\u0442\u043e \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u043d\u0430 KMP, \u043a\u0440\u043e\u043c\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u0431\u044f. \u0428\u0443\u0447\u0443, \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u043d\u0435 \u0432\u0441\u0435. \u041d\u043e \u043c\u044b, Android-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0438 \u043b\u044e\u0431\u0438\u0442\u0435\u043b\u0438 DI, \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 KMP \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 DI.<\/p>\n<p>\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e Kotlin DI, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0443\u0442 \u0434\u043b\u044f \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c. \u0421\u0430\u043c\u044b\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0432 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u2014 \u044d\u0442\u043e <a href=\"https:\/\/insert-koin.io\/\">Koin<\/a>. \u041d\u043e \u0443 \u043d\u0430\u0441 \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u0440\u043e <a href=\"https:\/\/kosi-libs.org\/kodein\/7.19\/index.html\">Kodein<\/a>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e Kodein \u0432 KMP \u043c\u044b \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c.<\/p>\n<h2>\u041a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c<\/h2>\n<p>\u0412\u0441\u0451, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 KMP \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c Kodein \u0432 common source set:<\/p>\n<pre><code class=\"kotlin\">sourceSets {    val commonMain by getting {        dependencies {            implementation(libs.kodein)  ...        }    } }<\/code><\/pre>\n<h2>\u0422\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043d\u0430 \u043a\u043e\u0448\u043a\u0430\u0445<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c Kodein \u0432 KMP \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u043f\u043e\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043c \u0435\u0433\u043e. \u042f \u0432\u0437\u044f\u043b \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0442 JetBrains <a href=\"https:\/\/github.com\/Kotlin\/kmm-production-sample\">KMM RSS Reader<\/a><strong>.<\/strong><\/p>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f DI, \u0442\u043e \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9b5\/af0\/aaa\/9b5af0aaa26f16eaa50d73b635b9a73f.png\" width=\"2198\" height=\"1372\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9b5\/af0\/aaa\/9b5af0aaa26f16eaa50d73b635b9a73f.png\"\/><\/figure>\n<p>\u041f\u043e \u0441\u0445\u0435\u043c\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>androidApp<\/code> \u0435\u0441\u0442\u044c DI (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Koin), \u0438 \u043e\u043d \u0431\u0435\u0440\u0451\u0442 \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u044b, \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0437 shared \u043c\u043e\u0434\u0443\u043b\u044f \u0438\u0437 source set\u2019\u043e\u0432 <code>androidMain<\/code> \u0438 <code>commonMain<\/code>.<\/p>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Kodein \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u043a\u043e\u0434 \u043d\u0430  Kotlin, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 <code>androidApp<\/code>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/58e\/9a2\/4e4\/58e9a24e47c7537c7673a6d64d0e9990.png\" width=\"2200\" height=\"1372\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/58e\/9a2\/4e4\/58e9a24e47c7537c7673a6d64d0e9990.png\"\/><\/figure>\n<p>\u041d\u0430 \u0441\u0445\u0435\u043c\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c DI Kodein \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 Kotlin.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f DI \u0433\u0440\u0430\u0444 (\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440) \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u0438\u043b\u0438 source set:<\/p>\n<ul>\n<li>\n<p>\u0432 commonMain \u0431\u0443\u0434\u0435\u0442 DI \u0441 \u0441\u0430\u043c\u044b\u043c\u0438 \u0431\u0430\u0437\u043e\u0432\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438 \u2014 \u043e\u043d\u0438 \u043e\u0431\u0449\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0438 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043d\u0438 \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c;<\/p>\n<\/li>\n<li>\n<p>\u0432 androidMain \u0438 iosMain \u0431\u0443\u0434\u0443\u0442 DI \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b \u0441 \u043e\u0431\u0449\u0438\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b. \u042d\u0442\u0438 DI \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c\u0438 \u043a \u0431\u0430\u0437\u043e\u0432\u043e\u043c\u0443 \u0438\u0437 commonMain;<\/p>\n<\/li>\n<li>\n<p>androidApp \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u0432\u043e\u0439 DI, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a DI \u0438\u0437 shared \u043c\u043e\u0434\u0443\u043b\u044f androidMain;<\/p>\n<\/li>\n<li>\n<p>iosApp \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e Kodein \u0432 iOS \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<\/p>\n<\/li>\n<\/ul>\n<h2>shared-commonMain<\/h2>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e DI \u0438\u0437 shared \u043c\u043e\u0434\u0443\u043b\u044f \u0432 commonMain \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445.<\/p>\n<pre><code class=\"kotlin\">fun sharedCommonDI() = DI {    import(sharedCommonModule()) }  fun sharedCommonModule() = DI.Module(\"sharedCommonModule\") {    bind&lt;Json>() with singleton {        Json {            ignoreUnknownKeys = true            isLenient = true            encodeDefaults = false        }    }     bind&lt;FeedStorage>() with singleton {        FeedStorage(            settings = instance(),            json = instance(),        )    }     bind&lt;FeedLoader>() with singleton {        FeedLoader(            httpClient = instance(),            parser = instance(),        )  ...<\/code><\/pre>\n<p>\u0427\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 DI <code>sharedCommonDI<\/code> c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043c\u043e\u0434\u0443\u043b\u0435\u043c <code>sharedCommonModule<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432\u0441\u0435 \u043e\u0431\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>JSON<\/code>, <code>FeedStorage<\/code>, <code>FeedLoader<\/code> \u0438 \u0434\u0440.<\/p>\n<\/li>\n<\/ul>\n<p>\u0417\u0434\u0435\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0433\u0440\u0430\u0444 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043d\u0435 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u044b\u043c.<\/p>\n<ol>\n<li>\n<p><code>FeedStorage<\/code> \u0438\u043c\u0435\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c <code>JSON<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0435\u0441\u0442\u044c \u0432 \u044d\u0442\u043e\u043c \u0436\u0435 DI, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c <code>settings<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u0442 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c DI. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>Settings<\/code> \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0445 source set\u2019\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e <code>FeedLoader<\/code>. \u041e\u043d \u0438\u043c\u0435\u0435\u0442 \u043e\u0431\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u044d\u0442\u043e\u043c DI \u0433\u0440\u0430\u0444\u0435. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>HttpClient<\/code> \u0438 <code>FeedParser<\/code> \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0445 source set\u2019\u0430\u0445.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u0443\u044e \u0448\u0442\u0443\u043a\u0443 \u043d\u0430\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u0442\u043e\u043c \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 androidApp \u0432 extend-\u043c\u0435\u0442\u043e\u0434\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 (\u0434\u0430\u043b\u044c\u0448\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u044d\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0443).<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 <code>sharedCommonDI<\/code>  \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u043c Kotlin \u043a\u043e\u0434\u0435, \u0431\u0435\u0437 Android \u0438\u043b\u0438 iOS \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0438, \u0430 \u0432\u0441\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0445 source set\u2019\u0430\u0445. \u041d\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0433\u0440\u0430\u0444 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<h2>shared-androidMain<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c DI \u0434\u043b\u044f Android-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 shared-\u043c\u043e\u0434\u0443\u043b\u0435. Android-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0443\u0442:<\/p>\n<ul>\n<li>\n<p>SharedPreferencesSettings,<\/p>\n<\/li>\n<li>\n<p>AndroidHttpClient.<\/p>\n<\/li>\n<li>\n<p>AndroidFeedParser.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"kotlin\">fun sharedAndroidDI() = DI {     import(sharedAndroidModule())     extend(di = sharedCommonDI()) }  fun sharedAndroidModule() = DI.Module(\"sharedAndroidModule\") {     bind&lt;Settings>() with singleton {         SharedPreferencesSettings(             delegate = instance(arg = RSS_READER_PREF_KEY),         )     }      bind&lt;HttpClient>() with singleton {         AndroidHttpClient(withLog = true)     }      bind&lt;FeedParser>() with singleton {         AndroidFeedParser()     } }<\/code><\/pre>\n<p><code>sharedAndroidDI<\/code> \u2014 \u044d\u0442\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 DI \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a <code>sharedCommonDI<\/code>. \u0414\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043c\u044b \u0435\u0433\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 extend. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, <code>sharedAndroidDI<\/code> \u0438\u043c\u0435\u0435\u0442 \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 Android-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4d9\/0f7\/58f\/4d90f758f728e7e00439f6441ccb592c.png\" width=\"1460\" height=\"780\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4d9\/0f7\/58f\/4d90f758f728e7e00439f6441ccb592c.png\"\/><\/figure>\n<h2>shared-iosMain<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0447\u0430\u0441\u0442\u0438 <code>iosMain<\/code>. \u0417\u0434\u0435\u0441\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e Android DI \u0433\u0440\u0430\u0444\u0443. \u0423 iOS-\u0447\u0430\u0441\u0442\u0438 \u0431\u0443\u0434\u0443\u0442 \u0441\u0432\u043e\u0438 iOS-\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<ul>\n<li>\n<p>NSUserDefaultsSettings,<\/p>\n<\/li>\n<li>\n<p>IosHttpClient,<\/p>\n<\/li>\n<li>\n<p>IosFeedParser.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"kotlin\">fun sharedIosDI() = DI {     import(sharedIosModule())     extend(di = sharedCommonDI()) }  fun sharedIosModule() = DI.Module(\"sharedIosModule\") {     bind&lt;Settings>() with singleton {         NSUserDefaultsSettings(             delegate = NSUserDefaults.standardUserDefaults(),         )     }      bind&lt;HttpClient>() with singleton {         IosHttpClient(withLog = true)     }      bind&lt;FeedParser>() with singleton {         IosFeedParser()     } }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u0436\u0435 <code>sharedIosDI<\/code> \u2014 \u044d\u0442\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 DI \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a <code>sharedCommonDI<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448\u0430 \u0441\u0445\u0435\u043c\u0430 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0434\u043e \u0442\u0430\u043a\u043e\u0439:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/abf\/cfd\/b6b\/abfcfdb6b99c291a32e373f89fb2bc78.png\" width=\"1460\" height=\"782\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/abf\/cfd\/b6b\/abfcfdb6b99c291a32e373f89fb2bc78.png\"\/><\/figure>\n<h2>androidApp<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043c\u043e\u0434\u0443\u043b\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>androidApp<\/code>. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 DI \u0432\u0441\u0435\u0433\u043e Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043c\u044b \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432 <code>Application<\/code> \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 <code>DIAware<\/code>.<\/p>\n<pre><code class=\"kotlin\">class App : Application(), Configuration.Provider, DIAware {     override val di: DI = AppDI(app = this)     ... }  object AppDI {    operator fun invoke(app: App) = DI {        import(androidXModule(app))        extend(di = sharedAndroidDI(), copy = All)    } }<\/code><\/pre>\n<p><code>AppDI<\/code> \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c DI \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a <code>sharedAndroidDI<\/code>. \u041f\u043e\u043c\u0438\u043c\u043e \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0447\u0435\u0433\u043e, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u044e\u0434\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0434\u043b\u044f Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 <code>androidXModule<\/code>. <code>androidXModule<\/code> \u2014 \u044d\u0442\u043e \u043c\u043e\u0434\u0443\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0434\u0451\u0442 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 Kodein \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043a\u043e \u0432\u0441\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u043c, \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a <code>Resources<\/code>, <code>ContentResolver<\/code>, <code>Looper<\/code>, <code>AlarmManager<\/code>, <code>NotificationManager<\/code> \u0438 \u043c\u043d\u043e\u0433\u0438\u043c \u0434\u0440\u0443\u0433\u0438\u043c. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u0433\u0440\u0430\u0444 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/09b\/1a3\/2b6\/09b1a32b6111feafe680b69edf2a3d9b.png\" width=\"2198\" height=\"1372\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/09b\/1a3\/2b6\/09b1a32b6111feafe680b69edf2a3d9b.png\"\/><\/figure>\n<h2>iosApp<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043d\u0430 iOS. \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435: Kodein \u043f\u043e\u0434 iOS \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e Kotlin-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0433\u043e, \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c inline-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 reified-\u0442\u0438\u043f\u0430\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0430\u0448 Kodein DI \u0433\u0440\u0430\u0444 \u0432 \u043d\u0435\u043a\u0443\u044e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e. \u041f\u043e\u043a\u0430\u0436\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c.<\/p>\n<p>\u0412\u0432\u0435\u0434\u0451\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Dependencies<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u043e\u0434\u0443\u043b\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>iosApp<\/code> (\u043a\u0430\u043a \u0438 <code>androidApp<\/code>) \u043d\u0443\u0436\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u2014 <code>FeedStore<\/code>. \u0412\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u2014 \u044d\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>provideFeedStore<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>FeedStore<\/code>.<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>DependenciesImpl<\/code> \u0431\u0443\u0434\u0435\u0442 \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 Kodein \u2014 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 androidApp.<\/p>\n<pre><code class=\"kotlin\">object DependenciesFactory {    fun create(): Dependencies = DependenciesImpl() }  interface Dependencies {    fun provideFeedStore(): FeedStore }  class DependenciesImpl : Dependencies {     private val di: DI by lazy { sharedIosDI() }     override fun provideFeedStore(): FeedStore {        return di.direct.instance()    } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 Xcode \u0438 \u043c\u0435\u043d\u044f\u0435\u043c <code>RSSApp<\/code>. \u041d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>Dependencies<\/code> \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 <code>create<\/code>. \u0417\u0430\u0442\u0435\u043c \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u043d\u0430\u0448 <code>FeedStore<\/code> \u0447\u0435\u0440\u0435\u0437 <code>provideFeedStore<\/code>.<\/p>\n<pre><code class=\"swift\">@main class RSSApp: App {     let dependencies: Dependencies     let store: ObservableFeedStore          required init() {         deps = DependenciesFactory.shared.create()         store = ObservableFeedStore(store: dependencies.provideFeedStore())     }        var body: some Scene {         WindowGroup {             RootView().environmentObject(store)         }     } }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043f\u0430\u0442\u0442\u0435\u0440\u043d <code>Service Locator<\/code>. \u041d\u043e Kodein \u0438 \u0432 Android- \u043a\u043b\u0430\u0441\u0441\u0430\u0445 (Activity, Fragment) \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a <code>Service Locator<\/code>. \u0422\u0430\u043a \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0435\u0433\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 \u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0431\u0443\u0436\u0434\u0430\u0442\u044c \u0445\u043e\u043b\u0438\u0432\u0430\u0440\u043d\u044b\u0439 \u0441\u043f\u043e\u0440.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0445\u0435\u043c\u0443. \u0423 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0447\u0442\u043e-\u0442\u043e \u0442\u0430\u043a\u043e\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/48c\/528\/699\/48c52869984f933b66f301eee50abc6a.png\" width=\"2404\" height=\"1370\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/48c\/528\/699\/48c52869984f933b66f301eee50abc6a.png\"\/><\/figure>\n<h2>\u0427\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u043f\u043e \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438:<\/p>\n<ul>\n<li>\n<p>\u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u0438 source set\u2019\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0432\u043e\u0439 DI \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440;<\/p>\n<\/li>\n<li>\n<p>\u0432 \u0438\u0442\u043e\u0433\u0435 \u0432\u0435\u0441\u044c Kotlin \u043a\u043e\u0434 \u043f\u043e\u043a\u0440\u044b\u0442 Kodein\u2019\u043e\u043c, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e androidApp;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043b\u044f iosApp \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0440\u0443\u0436\u0443 \u043e\u0442\u0434\u0430\u0432\u0430\u043b \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u041d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 DI \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 GitHub: <a href=\"https:\/\/github.com\/makzimi\/kmm-sample-with-kodein-di\">https:\/\/github.com\/makzimi\/kmm-sample-with-kodein-di<\/a><\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0433\u0443 \u043f\u043e\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u0432\u0438\u0434\u0435\u043e \u043e\u0442 \u0410\u043d\u0438 \u0416\u0430\u0440\u043a\u043e\u0432\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432 \u0446\u0435\u043b\u043e\u043c \u043f\u0440\u043e DI \u0432 KMM \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438: <a href=\"https:\/\/www.youtube.com\/watch?v=JtUJc4WYObo\">https:\/\/www.youtube.com\/watch?v=JtUJc4WYObo<\/a><\/p>\n<h2>Kodein \u0432 Compose<\/h2>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 KMM, Jetpack Compose \u2014 \u044d\u0442\u043e \u0443\u0436\u0435 \u043d\u0435 \u0447\u0442\u043e-\u0442\u043e \u0441\u0443\u043f\u0435\u0440\u043d\u043e\u0432\u043e\u0435 \u0438 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0435. \u041d\u0430 Jetpack Compose \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u0438\u043b\u0438, \u043a\u0430\u043a \u0438 \u043d\u0430\u0448, \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c DI Kodein \u043a \u043d\u0430\u0448\u0435\u043c\u0443 Compose \u043a\u043e\u0434\u0443.<\/p>\n<p>\u0422\u0443\u0442\u044c \u0435\u0441\u0442\u044c 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439.<\/p>\n<ul>\n<li>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u2014 \u0435\u0441\u043b\u0438 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0435\u0449\u0451 \u043d\u0430 Fragment\/View \u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Compose \u0447\u0435\u0440\u0435\u0437 <code>ComposeView<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u2014 \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430 Compose.<\/p>\n<\/li>\n<\/ul>\n<h2>ComposeView<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>ComposeView<\/code>, \u0442\u043e \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0438\u043b\u0438 \u0430\u043a\u0442\u0438\u0432\u0438\u0442\u0438. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <code>ViewModel<\/code> \u0432\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435, Kodein \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0439 \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>viewModel<\/code>.<\/p>\n<pre><code class=\"kotlin\">inline fun &lt;F, reified VM> F.viewModel(    noinline ownerProducer: () -> ViewModelStoreOwner = { this },    tag: Any? = null, ): Lazy&lt;VM> where F : Fragment, F : DIAware, VM : ViewModel {    return createViewModelLazy(        viewModelClass = VM::class,        storeProducer = { ownerProducer().viewModelStore },        factoryProducer = {            object : ViewModelProvider.Factory {                override fun &lt;T : ViewModel> create(modelClass: Class&lt;T>): T {                    val vmProvider = direct.provider&lt;VM>(tag)                    return vmProvider() as T                }            }        }    ) }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 <code>F : DIAware<\/code>. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u0432\u0430\u0441 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>DIAware<\/code> \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<\/p>\n<p>\u0418 \u0434\u0430\u043b\u044c\u0448\u0435, \u043d\u0430 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 <code>val vmProvider = *direct*.*provider*&lt;VM>(tag)<\/code>, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 <code>ViewModel<\/code> \u0438\u0437 DI \u0433\u0440\u0430\u0444\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c Kodein \u0443\u043c\u0435\u0435\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u044c <code>ViewModel<\/code> \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0442\u0435\u0439\u0442 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0435\u0440\u0435\u0437 <code>collectAsStateWithLifecycle<\/code>) \u0438\u0437 <code>ViewModel<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 <code>ComposeView<\/code>.<\/p>\n<pre><code class=\"kotlin\">view.setContent { val uiState by viewModel.uiState.collectAsStateWithLifecycle()     setContent {         AppTheme {             MainScreen(                 state = uiState,                 di = di,             )         }     } }<\/code><\/pre>\n<p>\u0414\u043b\u044f <code>Activity<\/code> \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435. \u041f\u0440\u0430\u0432\u0434\u0430 \u043e\u043d\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043e \u043a <code>AppCompatActivity<\/code>, \u0430 \u043d\u0435 \u043a <code>ComponentActivity<\/code>. \u041d\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0451 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435, \u0441 \u044d\u0442\u0438\u043c \u043d\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 DI \u0432 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0441\u043b\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f. \u041d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u0433\u043b\u0443\u0431\u0436\u0435: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DI \u0432 Composable-\u043c\u0435\u0442\u043e\u0434\u0430\u0445.<\/p>\n<h2>Compose \u044d\u043a\u0440\u0430\u043d<\/h2>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441: \u0430 \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u043e \u043d\u0430\u043c? \u0417\u0430\u0447\u0435\u043c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0438\u0445\u0430\u0442\u044c Kodein \u0432 \u043d\u0430\u0448 Compose-\u043a\u043e\u0434?<\/p>\n<p>\u041e\u0442\u0432\u0435\u0447\u0443 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0442\u0430\u043a: \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e, \u043c\u043e\u0436\u0435\u0442, \u0438 \u043d\u0435 \u043d\u0430\u0434\u043e. \u041a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0447\u0438\u0449\u0435 \u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0442\u0430\u0449\u0438\u0442\u044c \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a. \u041d\u043e, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0445\u043e\u0442\u0435\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <code>CompositionLocal<\/code> \u0438 \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u0438\u0439\u0442\u0438 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043f\u043e\u0440\u0442\u044f\u043d\u043a\u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u044d\u043a\u0440\u0430\u043d\u0430\u0445:<\/p>\n<pre><code class=\"kotlin\">CompositionLocalProvider(             LocalExoPlayerFactory provides exoPlayerFactory,             LocalTimeformatter provides timeFormatter,             LocalRetryCondition provides retryCondition, ...             LocalListFilter provides listFilter,             ) {           MainScreen(uiState)         }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0438 \u0442\u0430\u043a \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 DI. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DI, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d.<\/p>\n<p>Kodein \u0442\u043e\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 <code>CompositionLocal<\/code>. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e <code>CompositionLocal<\/code> \u2014 \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u043d\u0435\u044f\u0432\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Compose-\u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b Kodein, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c.<\/p>\n<pre><code class=\"bash\">implementation 'org.kodein.di:kodein-di-framework-compose:7.18.0'<\/code><\/pre>\n<h2>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 Compose \u0432\u0438\u0434\u0436\u0435\u0442\u0435<\/h2>\n<p>\u0415\u0441\u0442\u044c 3 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430, \u043a\u0430\u043a \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 Compose:<\/p>\n<ul>\n<li>\n<p>\u0447\u0435\u0440\u0435\u0437 <code>withDI<\/code>, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 DI;<\/p>\n<\/li>\n<li>\n<p>\u0447\u0435\u0440\u0435\u0437 <code>withDI<\/code>, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u043c\u043e\u0434\u0443\u043b\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0447\u0435\u0440\u0435\u0437 <code>subDI<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431. \u041e\u0431\u0435\u0440\u043d\u0451\u043c \u043d\u0430\u0448 \u0432\u0438\u0434\u0436\u0435\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434 <code>withDI<\/code>.<\/p>\n<pre><code class=\"kotlin\">@Composable fun MainScreen( state: UiState,     di: DI, ) = withDI(di) { Column { ContentView() BorromView()    } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u044b <code>ContentView<\/code> \u0438 <code>BottomView<\/code> \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0437 Kodein.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431: \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043d\u0435 \u0432\u0435\u0441\u044c DI, \u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438. \u042d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"kotlin\">@Composable fun MainScreen(state: UiState) = withDI(aModule, bModule) {    Column {        ContentView()        BottomView()    } }<\/code><\/pre>\n<p>\u041d\u0435 \u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0432 \u043a\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0434\u043b\u044f \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>\u0422\u0440\u0435\u0442\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 <code>subDI<\/code>. \u041e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443, \u0447\u0442\u043e \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 <code>subDI<\/code> \u0438\u043b\u0438 <code>subDI<\/code> \u0434\u043b\u044f \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432. <code>subDI<\/code> \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 DI \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e DI \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e \u0432\u0441\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e DI. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>subDI<\/code>, \u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u043a\u0430\u043a SubComponent \u0438\u0437 Dagger.<\/p>\n<pre><code class=\"kotlin\">@Composable fun ContentView() {     subDI(         diBuilder = { bindSingleton { UserDataRepository() } }     ) {         Column {             Row {                 \/\/...             }             }     } }<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 <code>subDI<\/code> \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 DI, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u043b \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 <code>withDI()<\/code>. \u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c <code>IllegalStateException<\/code>.<\/p>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u0421ompose-\u0432\u0438\u0434\u0436\u0435\u0442\u0435<\/h2>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 <code>localDI()<\/code>. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>localDI()<\/code>, \u043e\u043d \u0432\u0435\u0440\u043d\u0451\u0442 \u043d\u0430\u043c DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0438\u0437 <code>CompositionLocal<\/code>. \u0414\u0430\u043b\u0435\u0435 \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b <code>instance()<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<pre><code class=\"kotlin\">@Composable fun ContentView() {    ...    val di = localDI()    val service: MyService by di.instance()    ... }<\/code><\/pre>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f Composable-\u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>rememberDI<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c <code>remember<\/code> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u043d\u0430\u0448\u0443 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u0435 \u0434\u0451\u0440\u0433\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440.<\/p>\n<pre><code class=\"kotlin\">@Composable fun ContentView() {    ...    val service: MyService by rememberDI { instance() }    ... }<\/code><\/pre>\n<p>\u0422\u0440\u0435\u0442\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u043c\u0435\u0442\u043e\u0434\u044b <code>rememberInstance<\/code>, <code>rememberNamedInstance<\/code>, <code>rememberFactory<\/code>, <code>rememberProvider<\/code>. \u041e\u043d\u0438 \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u043d\u0430\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c. \u041d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e.<\/p>\n<pre><code class=\"kotlin\">@Composable fun ContentView() {     val service: MyService by rememberInstance() }<\/code><\/pre>\n<p>\u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0432\u0441\u0451 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f Jetpack Compose, \u0430 \u043d\u0435 Compose Multiplatform. \u041d\u043e \u0434\u0443\u043c\u0430\u044e, \u0434\u0435\u043b\u043e \u043d\u0435 \u0437\u0430 \u0433\u043e\u0440\u0430\u043c\u0438.<\/p>\n<h2>\u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u0438\u0442\u043e\u0433 \u043f\u0440\u043e Kodein \u0432 Compose<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0435\u0437\u044e\u043c\u0438\u0440\u0443\u0435\u043c, \u0437\u0430\u0447\u0435\u043c \u0438 \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Kodein \u0432 Compose.<\/p>\n<ol>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DI \u0432 Compose \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u041d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445.<\/p>\n<\/li>\n<li>\n<p>Kodein \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u043d\u0430\u0448\u0438 Compose-\u0432\u0438\u0434\u0436\u0435\u0442\u044b \u0441\u0432\u043e\u0438\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c. \u0411\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u043e\u0439 \u043a\u043e\u0434\u0430 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e \u0432\u0441\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u044b \u0438\u043c\u0435\u044e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u044b \u043a\u043e \u0432\u0441\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c.<\/p>\n<\/li>\n<li>\n<p>Kodein \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c subDI, \u0442.\u0435. \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 DI-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0440\u0430\u0437\u0443 \u0432 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 DI.<\/p>\n<\/li>\n<\/ol>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442, \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0438\u0437 \u0434\u0432\u0443\u0445 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u0442\u0435\u043c: Kodein \u0432 \u041a\u041cP \u0438 Kodein \u0432 Jetpack Compose. \u041d\u043e \u044f \u0438\u0445 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043b, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u0438 \u0442\u0435\u043c\u044b \u2014 \u0431\u0443\u0434\u0443\u0449\u0435\u0435 Android-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0414\u043b\u044f \u043a\u043e\u0433\u043e-\u0442\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u043e \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u043c, \u043d\u043e \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u2014 \u044d\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0435 \u0431\u0443\u0434\u0443\u0449\u0435\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0430\u0436\u043d\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u0438\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u0445, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0441 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 DI.<\/p>\n<p>\u041c\u044b \u0443\u0432\u0438\u0434\u0435\u043b\u0438, \u0447\u0442\u043e Kodein \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043f\u043e \u0432\u0441\u0435\u043c\u0443 Kotlin-\u043a\u043e\u0434\u0443, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043c\u043e\u0434\u0443\u043b\u044f\u0445 Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c, \u0447\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Kodein \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u043a\u0430\u0447\u0430\u0442\u044c \u0441\u0432\u043e\u0439 Compose-\u043a\u043e\u0434 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e \u0432\u0441\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c. \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u0438 \u0434\u043b\u044f \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<blockquote>\n<p>\u0411\u0443\u0434\u0443 \u043b\u0438 \u044f \u0441\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Kodein \u0432 KMM \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445? \u0414\u0430, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u0438 \u043d\u0435\u0442. \u0425\u043e\u0442\u044f \u043d\u0430\u0434\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0438 \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b. Koin \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f KMP. \u0418 \u0432\u0441\u0435 \u043c\u044b \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u043c \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0442\u0435\u043c, \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u0442 \u043b\u0438 Dagger \u043d\u0430 KMM.<\/p>\n<p>\u0411\u0443\u0434\u0435\u043c \u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Kodein \u0432 Jetpack Compose? \u041f\u043e\u043a\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Kodein \u0432\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u0445. \u041d\u043e \u0441\u043e\u0431\u043b\u0430\u0437\u043d \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c CompositionLocal \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u044b \u043d\u0430 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443 Kodein \u043e\u0447\u0435\u043d\u044c \u0432\u0435\u043b\u0438\u043a. \u0415\u0441\u043b\u0438 Kodein \u043d\u0430\u0447\u043d\u0451\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0438 Compose Multiplatform, \u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0448\u0435 \u043c\u043d\u0435\u043d\u0438\u0435.<\/p>\n<\/blockquote>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u044e! \u0410 \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043b\u0435\u043d\u044c \u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u044b, \u043a\u0430\u043a \u044d\u0442\u043e\u0442, \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u043c\u043e\u0439 \u0422\u0413 \u043a\u0430\u043d\u0430\u043b\u00a0<a href=\"https:\/\/t.me\/mobilefiction\">\u041c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0435 \u0447\u0442\u0438\u0432\u043e<\/a>. \u0422\u0430\u043c \u044f \u0434\u0435\u043b\u044e\u0441\u044c \u0441\u0432\u043e\u0438\u043c\u0438 \u043c\u044b\u0441\u043b\u044f\u043c\u0438, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u0440\u043e Android-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e.<\/p>\n<p>\u0410 \u043d\u043e\u0432\u043e\u0441\u0442\u044f\u043c\u0438 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432 Dodo \u0432 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043c\u044b \u0434\u0435\u043b\u0438\u043c\u0441\u044f \u0432\u00a0<a href=\"https:\/\/t.me\/dodoMobile\">Dodo Mobile<\/a>.<\/p>\n<p>\u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0438\u0437 \u0446\u0438\u043a\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u043f\u0440\u043e Kodein DI \u0434\u043b\u044f Android:<\/p>\n<p>\u0427\u0430\u0441\u0442\u044c 1: <a href=\"https:\/\/habr.com\/ru\/companies\/dododev\/articles\/755288\/\">Kodein DI \u0434\u043b\u044f Android. \u041e\u0441\u043d\u043e\u0432\u044b API <\/a><\/p>\n<p>\u0427\u0430\u0441\u0442\u044c 2: Kodein DI \u0434\u043b\u044f Android. KMP \u0438 Compose<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><\/p>\n<div class=\"tm-article-poll-container\"><!--[--><\/p>\n<div class=\"tm-article-poll tm-article-poll_variant-bordered\">\n<div class=\"tm-notice tm-notice_positive tm-article-poll__notice\"><!----><\/p>\n<div class=\"tm-notice__inner\"><!----><\/p>\n<div class=\"tm-notice__content\" data-test-id=\"notice-content\"><!--[--><span>\u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0440\u043e\u0441\u0435. <a rel=\"nofollow\" href=\"\/kek\/v1\/auth\/habrahabr\/?back=\/ru\/companies\/dododev\/articles\/766058\/&#038;hl=ru\">\u0412\u043e\u0439\u0434\u0438\u0442\u0435<\/a>, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430.<\/span><!--]--><\/div>\n<\/div>\n<\/div>\n<p><!--[--><\/p>\n<div class=\"tm-article-poll__header\">\u041a\u0430\u043a\u0438\u043c\u0438 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u043c\u0438 \u0432\u044b \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435\u0441\u044c \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435?<\/div>\n<div class=\"tm-article-poll__answers\"><!--[--><\/p>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">22.73% <\/span><span class=\"tm-article-poll__answer-label\">\u042f \u0432\u043f\u0435\u0440\u0435\u0434\u0438 \u043f\u043b\u0430\u043d\u0435\u0442\u044b \u0432\u0441\u0435\u0439: KMP \u0438 Compose Multiplatform<\/span><span class=\"tm-article-poll__answer-votes\">5<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 22.73%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">4.55% <\/span><span class=\"tm-article-poll__answer-label\">\u042f \u0443\u0436\u0435 \u044d\u043a\u043e\u043d\u043e\u043c\u043b\u044e \u043a\u043e\u0434: \u0442\u043e\u043b\u044c\u043a\u043e KMP<\/span><span class=\"tm-article-poll__answer-votes\">1<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 4.55%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">31.82% <\/span><span class=\"tm-article-poll__answer-label\">\u0414\u0435\u043b\u0430\u0435\u043c \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u043e: \u0442\u043e\u043b\u044c\u043a\u043e Jetpack Compose<\/span><span class=\"tm-article-poll__answer-votes\">7<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 31.82%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent tm-article-poll__answer-percent_winning\">40.91% <\/span><span class=\"tm-article-poll__answer-label\">\u0422\u0438\u0448\u0435 \u0435\u0434\u0435\u0448\u044c \u2014 \u0434\u0430\u043b\u044c\u0448\u0435 \u0431\u0443\u0434\u0435\u0448\u044c: \u043f\u043e\u043a\u0430 \u043d\u0438 KMP, \u043d\u0438 Compose<\/span><span class=\"tm-article-poll__answer-votes\">9<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress tm-article-poll__answer-progress_winning\" style=\"width: 40.91%\"><\/div>\n<\/div>\n<\/div>\n<p><!--]--><\/div>\n<div class=\"tm-article-poll__stats\"> \u041f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 22 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.    \u0412\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u043b\u0438\u0441\u044c 2 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. <\/div>\n<p><!--]--><\/div>\n<p><!--]--><\/div>\n<p> \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\/766058\/\"> https:\/\/habr.com\/ru\/articles\/766058\/<\/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<figure class=\"full-width\"><\/figure>\n<p>\u0411\u044b\u0442\u044c \u0432 \u0430\u0432\u0430\u043d\u0433\u0430\u0440\u0434\u0435 \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u2014 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u0430\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u043e\u0433\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u0443\u0436\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u044f\u0442 \u043d\u0430 Jetpack Compose, \u0430 \u0441\u0430\u043c\u044b\u0435 \u0441\u043c\u0435\u043b\u044b\u0435 \u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0434\u0430\u0436\u0435 \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 KMP. \u041c\u044b \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0414\u0440\u0438\u043d\u043a\u0438\u0442 \u0442\u043e\u0436\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 Jetpack Compose (\u0441 KMP \u043f\u043e\u043a\u0430 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434).<\/p>\n<p>\u041d\u0443 \u0438 \u043a\u0430\u043a \u0436\u0435 \u0436\u0438\u0442\u044c \u0441\u043e \u0432\u0441\u0435\u043c \u044d\u0442\u0438\u043c \u0431\u0435\u0437 DI? \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043d\u0438\u043a\u0430\u043a. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c DI Kodein \u0432 Kotlin Multiplatform \u0438 Jetpack Compose.<\/p>\n<p>\u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0438\u0437 \u0446\u0438\u043a\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u043f\u0440\u043e Kodein DI \u0434\u043b\u044f Android:<\/p>\n<p>\u0427\u0430\u0441\u0442\u044c 1: <a href=\"https:\/\/habr.com\/ru\/companies\/dododev\/articles\/755288\/\">Kodein DI \u0434\u043b\u044f Android. \u041e\u0441\u043d\u043e\u0432\u044b API <\/a><\/p>\n<p>\u0427\u0430\u0441\u0442\u044c 2: Kodein DI \u0434\u043b\u044f Android. KMP \u0438 Compose<\/p>\n<p>\u041f\u043e\u0433\u043d\u0430\u043b\u0438.<\/p>\n<h2>Kotlin Multiplatform<\/h2>\n<p><a href=\"https:\/\/kotlinlang.org\/docs\/multiplatform.html\">Kotlin Multiplatform<\/a> \u0432\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0448\u0443 \u0436\u0438\u0437\u043d\u044c, \u0432\u044b\u0431\u0438\u0432\u0430\u044f \u0434\u0432\u0435\u0440\u044c \u043d\u043e\u0433\u043e\u0439. \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439 \u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0432\u043d\u0435\u0434\u0440\u0438\u043b\u0438 \u0441\u0435\u0431\u0435 KMP \u2014 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043d\u043e, \u0441\u0443\u0434\u044f \u043f\u043e \u0442\u0435\u043c\u0430\u043c \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u043b\u0435\u0442, \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u0435, \u0431\u0443\u0434\u0442\u043e \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u043d\u0430 KMP, \u043a\u0440\u043e\u043c\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u0431\u044f. \u0428\u0443\u0447\u0443, \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u043d\u0435 \u0432\u0441\u0435. \u041d\u043e \u043c\u044b, Android-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0438 \u043b\u044e\u0431\u0438\u0442\u0435\u043b\u0438 DI, \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 KMP \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 DI.<\/p>\n<p>\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e Kotlin DI, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0443\u0442 \u0434\u043b\u044f \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c. \u0421\u0430\u043c\u044b\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0432 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u2014 \u044d\u0442\u043e <a href=\"https:\/\/insert-koin.io\/\">Koin<\/a>. \u041d\u043e \u0443 \u043d\u0430\u0441 \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u0440\u043e <a href=\"https:\/\/kosi-libs.org\/kodein\/7.19\/index.html\">Kodein<\/a>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e Kodein \u0432 KMP \u043c\u044b \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c.<\/p>\n<h2>\u041a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c<\/h2>\n<p>\u0412\u0441\u0451, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 KMP \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c Kodein \u0432 common source set:<\/p>\n<pre><code class=\"kotlin\">sourceSets {    val commonMain by getting {        dependencies {            implementation(libs.kodein)  ...        }    } }<\/code><\/pre>\n<h2>\u0422\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043d\u0430 \u043a\u043e\u0448\u043a\u0430\u0445<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c Kodein \u0432 KMP \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u043f\u043e\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043c \u0435\u0433\u043e. \u042f \u0432\u0437\u044f\u043b \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0442 JetBrains <a href=\"https:\/\/github.com\/Kotlin\/kmm-production-sample\">KMM RSS Reader<\/a><strong>.<\/strong><\/p>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f DI, \u0442\u043e \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u043e \u0441\u0445\u0435\u043c\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>androidApp<\/code> \u0435\u0441\u0442\u044c DI (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Koin), \u0438 \u043e\u043d \u0431\u0435\u0440\u0451\u0442 \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u044b, \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0437 shared \u043c\u043e\u0434\u0443\u043b\u044f \u0438\u0437 source set\u2019\u043e\u0432 <code>androidMain<\/code> \u0438 <code>commonMain<\/code>.<\/p>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Kodein \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u043a\u043e\u0434 \u043d\u0430  Kotlin, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 <code>androidApp<\/code>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041d\u0430 \u0441\u0445\u0435\u043c\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c DI Kodein \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 Kotlin.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f DI \u0433\u0440\u0430\u0444 (\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440) \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u0438\u043b\u0438 source set:<\/p>\n<ul>\n<li>\n<p>\u0432 commonMain \u0431\u0443\u0434\u0435\u0442 DI \u0441 \u0441\u0430\u043c\u044b\u043c\u0438 \u0431\u0430\u0437\u043e\u0432\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438 \u2014 \u043e\u043d\u0438 \u043e\u0431\u0449\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0438 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043d\u0438 \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c;<\/p>\n<\/li>\n<li>\n<p>\u0432 androidMain \u0438 iosMain \u0431\u0443\u0434\u0443\u0442 DI \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b \u0441 \u043e\u0431\u0449\u0438\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b. \u042d\u0442\u0438 DI \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c\u0438 \u043a \u0431\u0430\u0437\u043e\u0432\u043e\u043c\u0443 \u0438\u0437 commonMain;<\/p>\n<\/li>\n<li>\n<p>androidApp \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u0432\u043e\u0439 DI, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a DI \u0438\u0437 shared \u043c\u043e\u0434\u0443\u043b\u044f androidMain;<\/p>\n<\/li>\n<li>\n<p>iosApp \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e Kodein \u0432 iOS \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<\/p>\n<\/li>\n<\/ul>\n<h2>shared-commonMain<\/h2>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e DI \u0438\u0437 shared \u043c\u043e\u0434\u0443\u043b\u044f \u0432 commonMain \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445.<\/p>\n<pre><code class=\"kotlin\">fun sharedCommonDI() = DI {    import(sharedCommonModule()) }  fun sharedCommonModule() = DI.Module(\"sharedCommonModule\") {    bind&lt;Json>() with singleton {        Json {            ignoreUnknownKeys = true            isLenient = true            encodeDefaults = false        }    }     bind&lt;FeedStorage>() with singleton {        FeedStorage(            settings = instance(),            json = instance(),        )    }     bind&lt;FeedLoader>() with singleton {        FeedLoader(            httpClient = instance(),            parser = instance(),        )  ...<\/code><\/pre>\n<p>\u0427\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 DI <code>sharedCommonDI<\/code> c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043c\u043e\u0434\u0443\u043b\u0435\u043c <code>sharedCommonModule<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432\u0441\u0435 \u043e\u0431\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>JSON<\/code>, <code>FeedStorage<\/code>, <code>FeedLoader<\/code> \u0438 \u0434\u0440.<\/p>\n<\/li>\n<\/ul>\n<p>\u0417\u0434\u0435\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0433\u0440\u0430\u0444 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043d\u0435 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u044b\u043c.<\/p>\n<ol>\n<li>\n<p><code>FeedStorage<\/code> \u0438\u043c\u0435\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c <code>JSON<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0435\u0441\u0442\u044c \u0432 \u044d\u0442\u043e\u043c \u0436\u0435 DI, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c <code>settings<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u0442 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c DI. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>Settings<\/code> \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0445 source set\u2019\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e <code>FeedLoader<\/code>. \u041e\u043d \u0438\u043c\u0435\u0435\u0442 \u043e\u0431\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u044d\u0442\u043e\u043c DI \u0433\u0440\u0430\u0444\u0435. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>HttpClient<\/code> \u0438 <code>FeedParser<\/code> \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0445 source set\u2019\u0430\u0445.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u0443\u044e \u0448\u0442\u0443\u043a\u0443 \u043d\u0430\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u0442\u043e\u043c \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 androidApp \u0432 extend-\u043c\u0435\u0442\u043e\u0434\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 (\u0434\u0430\u043b\u044c\u0448\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u044d\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0443).<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 <code>sharedCommonDI<\/code>  \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u043c Kotlin \u043a\u043e\u0434\u0435, \u0431\u0435\u0437 Android \u0438\u043b\u0438 iOS \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0438, \u0430 \u0432\u0441\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0445 source set\u2019\u0430\u0445. \u041d\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0433\u0440\u0430\u0444 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<h2>shared-androidMain<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c DI \u0434\u043b\u044f Android-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 shared-\u043c\u043e\u0434\u0443\u043b\u0435. Android-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0443\u0442:<\/p>\n<ul>\n<li>\n<p>SharedPreferencesSettings,<\/p>\n<\/li>\n<li>\n<p>AndroidHttpClient.<\/p>\n<\/li>\n<li>\n<p>AndroidFeedParser.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"kotlin\">fun sharedAndroidDI() = DI {     import(sharedAndroidModule())     extend(di = sharedCommonDI()) }  fun sharedAndroidModule() = DI.Module(\"sharedAndroidModule\") {     bind&lt;Settings>() with singleton {         SharedPreferencesSettings(             delegate = instance(arg = RSS_READER_PREF_KEY),         )     }      bind&lt;HttpClient>() with singleton {         AndroidHttpClient(withLog = true)     }      bind&lt;FeedParser>() with singleton {         AndroidFeedParser()     } }<\/code><\/pre>\n<p><code>sharedAndroidDI<\/code> \u2014 \u044d\u0442\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 DI \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a <code>sharedCommonDI<\/code>. \u0414\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043c\u044b \u0435\u0433\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 extend. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, <code>sharedAndroidDI<\/code> \u0438\u043c\u0435\u0435\u0442 \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 Android-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><\/figure>\n<h2>shared-iosMain<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0447\u0430\u0441\u0442\u0438 <code>iosMain<\/code>. \u0417\u0434\u0435\u0441\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e Android DI \u0433\u0440\u0430\u0444\u0443. \u0423 iOS-\u0447\u0430\u0441\u0442\u0438 \u0431\u0443\u0434\u0443\u0442 \u0441\u0432\u043e\u0438 iOS-\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<ul>\n<li>\n<p>NSUserDefaultsSettings,<\/p>\n<\/li>\n<li>\n<p>IosHttpClient,<\/p>\n<\/li>\n<li>\n<p>IosFeedParser.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"kotlin\">fun sharedIosDI() = DI {     import(sharedIosModule())     extend(di = sharedCommonDI()) }  fun sharedIosModule() = DI.Module(\"sharedIosModule\") {     bind&lt;Settings>() with singleton {         NSUserDefaultsSettings(             delegate = NSUserDefaults.standardUserDefaults(),         )     }      bind&lt;HttpClient>() with singleton {         IosHttpClient(withLog = true)     }      bind&lt;FeedParser>() with singleton {         IosFeedParser()     } }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u0436\u0435 <code>sharedIosDI<\/code> \u2014 \u044d\u0442\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 DI \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a <code>sharedCommonDI<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448\u0430 \u0441\u0445\u0435\u043c\u0430 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0434\u043e \u0442\u0430\u043a\u043e\u0439:<\/p>\n<figure class=\"full-width\"><\/figure>\n<h2>androidApp<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043c\u043e\u0434\u0443\u043b\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>androidApp<\/code>. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 DI \u0432\u0441\u0435\u0433\u043e Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043c\u044b \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432 <code>Application<\/code> \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 <code>DIAware<\/code>.<\/p>\n<pre><code class=\"kotlin\">class App : Application(), Configuration.Provider, DIAware {     override val di: DI = AppDI(app = this)     ... }  object AppDI {    operator fun invoke(app: App) = DI {        import(androidXModule(app))        extend(di = sharedAndroidDI(), copy = All)    } }<\/code><\/pre>\n<p><code>AppDI<\/code> \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c DI \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a <code>sharedAndroidDI<\/code>. \u041f\u043e\u043c\u0438\u043c\u043e \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0447\u0435\u0433\u043e, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u044e\u0434\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0434\u043b\u044f Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 <code>androidXModule<\/code>. <code>androidXModule<\/code> \u2014 \u044d\u0442\u043e \u043c\u043e\u0434\u0443\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0434\u0451\u0442 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 Kodein \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043a\u043e \u0432\u0441\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u043c, \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a <code>Resources<\/code>, <code>ContentResolver<\/code>, <code>Looper<\/code>, <code>AlarmManager<\/code>, <code>NotificationManager<\/code> \u0438 \u043c\u043d\u043e\u0433\u0438\u043c \u0434\u0440\u0443\u0433\u0438\u043c. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u0433\u0440\u0430\u0444 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><\/figure>\n<h2>iosApp<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043d\u0430 iOS. \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435: Kodein \u043f\u043e\u0434 iOS \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e Kotlin-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0433\u043e, \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c inline-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 reified-\u0442\u0438\u043f\u0430\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0430\u0448 Kodein DI \u0433\u0440\u0430\u0444 \u0432 \u043d\u0435\u043a\u0443\u044e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e. \u041f\u043e\u043a\u0430\u0436\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c.<\/p>\n<p>\u0412\u0432\u0435\u0434\u0451\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Dependencies<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u043e\u0434\u0443\u043b\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>iosApp<\/code> (\u043a\u0430\u043a \u0438 <code>androidApp<\/code>) \u043d\u0443\u0436\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u2014 <code>FeedStore<\/code>. \u0412\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u2014 \u044d\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>provideFeedStore<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>FeedStore<\/code>.<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>DependenciesImpl<\/code> \u0431\u0443\u0434\u0435\u0442 \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 Kodein \u2014 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 androidApp.<\/p>\n<pre><code class=\"kotlin\">object DependenciesFactory {    fun create(): Dependencies = DependenciesImpl() }  interface Dependencies {    fun provideFeedStore(): FeedStore }  class DependenciesImpl : Dependencies {     private val di: DI by lazy { sharedIosDI() }     override fun provideFeedStore(): FeedStore {        return di.direct.instance()    } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 Xcode \u0438 \u043c\u0435\u043d\u044f\u0435\u043c <code>RSSApp<\/code>. \u041d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>Dependencies<\/code> \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 <code>create<\/code>. \u0417\u0430\u0442\u0435\u043c \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u043d\u0430\u0448 <code>FeedStore<\/code> \u0447\u0435\u0440\u0435\u0437 <code>provideFeedStore<\/code>.<\/p>\n<pre><code class=\"swift\">@main class RSSApp: App {     let dependencies: Dependencies     let store: ObservableFeedStore          required init() {         deps = DependenciesFactory.shared.create()         store = ObservableFeedStore(store: dependencies.provideFeedStore())     }        var body: some Scene {         WindowGroup {             RootView().environmentObject(store)         }     } }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043f\u0430\u0442\u0442\u0435\u0440\u043d <code>Service Locator<\/code>. \u041d\u043e Kodein \u0438 \u0432 Android- \u043a\u043b\u0430\u0441\u0441\u0430\u0445 (Activity, Fragment) \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a <code>Service Locator<\/code>. \u0422\u0430\u043a \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0435\u0433\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 \u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0431\u0443\u0436\u0434\u0430\u0442\u044c \u0445\u043e\u043b\u0438\u0432\u0430\u0440\u043d\u044b\u0439 \u0441\u043f\u043e\u0440.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0445\u0435\u043c\u0443. \u0423 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0447\u0442\u043e-\u0442\u043e \u0442\u0430\u043a\u043e\u0435:<\/p>\n<figure class=\"full-width\"><\/figure>\n<h2>\u0427\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u043f\u043e \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438:<\/p>\n<ul>\n<li>\n<p>\u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u0438 source set\u2019\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0432\u043e\u0439 DI \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440;<\/p>\n<\/li>\n<li>\n<p>\u0432 \u0438\u0442\u043e\u0433\u0435 \u0432\u0435\u0441\u044c Kotlin \u043a\u043e\u0434 \u043f\u043e\u043a\u0440\u044b\u0442 Kodein\u2019\u043e\u043c, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e androidApp;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043b\u044f iosApp \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0440\u0443\u0436\u0443 \u043e\u0442\u0434\u0430\u0432\u0430\u043b \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u041d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 DI \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 GitHub: <a href=\"https:\/\/github.com\/makzimi\/kmm-sample-with-kodein-di\">https:\/\/github.com\/makzimi\/kmm-sample-with-kodein-di<\/a><\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0433\u0443 \u043f\u043e\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u0432\u0438\u0434\u0435\u043e \u043e\u0442 \u0410\u043d\u0438 \u0416\u0430\u0440\u043a\u043e\u0432\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432 \u0446\u0435\u043b\u043e\u043c \u043f\u0440\u043e DI \u0432 KMM \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438: <a href=\"https:\/\/www.youtube.com\/watch?v=JtUJc4WYObo\">https:\/\/www.youtube.com\/watch?v=JtUJc4WYObo<\/a><\/p>\n<h2>Kodein \u0432 Compose<\/h2>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 KMM, Jetpack Compose \u2014 \u044d\u0442\u043e \u0443\u0436\u0435 \u043d\u0435 \u0447\u0442\u043e-\u0442\u043e \u0441\u0443\u043f\u0435\u0440\u043d\u043e\u0432\u043e\u0435 \u0438 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0435. \u041d\u0430 Jetpack Compose \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u0438\u043b\u0438, \u043a\u0430\u043a \u0438 \u043d\u0430\u0448, \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c DI Kodein \u043a \u043d\u0430\u0448\u0435\u043c\u0443 Compose \u043a\u043e\u0434\u0443.<\/p>\n<p>\u0422\u0443\u0442\u044c \u0435\u0441\u0442\u044c 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439.<\/p>\n<ul>\n<li>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u2014 \u0435\u0441\u043b\u0438 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0435\u0449\u0451 \u043d\u0430 Fragment\/View \u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Compose \u0447\u0435\u0440\u0435\u0437 <code>ComposeView<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u2014 \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430 Compose.<\/p>\n<\/li>\n<\/ul>\n<h2>ComposeView<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>ComposeView<\/code>, \u0442\u043e \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0438\u043b\u0438 \u0430\u043a\u0442\u0438\u0432\u0438\u0442\u0438. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <code>ViewModel<\/code> \u0432\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435, Kodein<\/p>\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-356947","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/356947","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=356947"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/356947\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}