{"id":43833,"date":"2019-12-24T08:56:11","date_gmt":"2019-12-23T23:56:11","guid":{"rendered":"https:\/\/www.charlezz.com\/?p=43833"},"modified":"2019-12-24T09:01:03","modified_gmt":"2019-12-24T00:01:03","slug":"databindingcomponent%ec%99%80-dagger2%ec%99%80-%ed%95%a8%ea%bb%98-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/charlezz.com\/?p=43833","title":{"rendered":"DataBindingComponent\uc640 Dagger2\uc640 \ud568\uaed8 \uc0ac\uc6a9\ud558\uae30"},"content":{"rendered":"<h1>DataBindingComponent\uc640 Dagger2\uc640 \ud568\uaed8 \uc0ac\uc6a9\ud558\uae30<\/h1>\n<p>\uc774\ubc88\uc5d0 \ub2e4\ub8f0 \ub0b4\uc6a9\uc740 <a href=\"https:\/\/www.charlezz.com\/?p=21509\">DatabindingComponent \uc0ac\uc6a9\ud558\uae30<\/a> 2\ud0c4\uc73c\ub85c DataBindingComponent\ub97c \uc758\uc874\uc131 \uc8fc\uc785 \ud504\ub808\uc784\uc6cc\ud06c\uc778 Dagger2\uc640 \ud568\uaed8 \uc0ac\uc6a9\ud558\ub294 \ubc29\ubc95\uc5d0 \ub300\ud574\uc11c \uc54c\uc544\ubcf8\ub2e4.<\/p>\n<h2>Prerequisite<\/h2>\n<ul style=\"list-style-type: disc;\">\n<li><a href=\"https:\/\/developer.android.com\/topic\/libraries\/data-binding\/?hl=ko\">\ub370\uc774\ud130\ubc14\uc778\ub529 \ub77c\uc774\ube0c\ub7ec\ub9ac<\/a><\/li>\n<li><a href=\"https:\/\/www.charlezz.com\/?p=21509\">DatabindingComponent \uc0ac\uc6a9\ud558\uae30<\/a><\/li>\n<li><a href=\"https:\/\/www.charlezz.com\/?p=1259\">Dagger2\ub97c \uc54c\uc544\ubcf4\uc790<\/a><\/li>\n<\/ul>\n<h2>DataBindingComponent \/w Dagger2<\/h2>\n<p><a href=\"https:\/\/developer.android.com\/reference\/android\/databinding\/DataBindingComponent\">DataBindingComponent \uacf5\uc2dd \ubb38\uc11c<\/a>\ub97c \ucc38\uc870\ud558\uba74, \ub2e4\uc74c\uacfc \uac19\uc740 \ub0b4\uc6a9\uc774 \uc788\ub2e4.<\/p>\n<blockquote>\n<p><span>If using Dagger 2, the developer should extend this interface and annotate the extended interface as a Component.<\/span><\/p>\n<\/blockquote>\n<p>Dagger2\ub97c \uc0ac\uc6a9\ud558\ub294 \uac1c\ubc1c\uc790\ub294 \uc774 \uc778\ud130\ud398\uc774\uc2a4\ub97c \ud655\uc7a5\ud558\uace0, @Component \uc560\ub178\ud14c\uc774\uc158\uc744 \ucd94\uac00\ud574 Dagger2\uc758 \ucef4\ud3ec\ub10c\ud2b8\ub85c \ud65c\uc6a9\ud560 \uc218 \uc788\ub2e4\ub294 \ub0b4\uc6a9\uc774\ub2e4.<\/p>\n<p>\ub2f9\uc5f0\ud55c \uc774\uc57c\uae30\uc9c0\ub9cc \uc778\ud130\ud398\uc774\uc2a4 \uae30\ubc18\uc73c\ub85c Dagger2\uc758 \ud504\ub85c\ube44\uc804 \uba54\uc11c\ub4dc\uc640 DataBindingComponent\uc758 getter\uba54\uc11c\ub4dc\ub97c \ucc38\uc870\ud558\ub294 \uad6c\uc870\uac00 \uac19\uae30 \ub54c\ubb38\uc5d0 Dagger2\ub97c \ud65c\uc6a9\ud560 \uc218 \uc788\ub2e4.<\/p>\n<p><a href=\"https:\/\/www.charlezz.com\/?p=21509\">DatabindingComponent \uc0ac\uc6a9\ud558\uae30<\/a>\uc758 \uc608\uc81c\ub97c Dagger2\ub97c \uc0ac\uc6a9\ud55c \uc608\uc81c\ub85c \ub2e4\uc74c\uacfc \uac19\uc774 \ub9ac\ud329\ud1a0\ub9c1\ud588\ub2e4.<\/p>\n<pre class=\"lang: decode:true\">@Component(modules = LifecycleModule.class)\r\npublic interface MyDatabindingComponent extends androidx.databinding.DataBindingComponent {\r\n    ClickBinding getClickBinding();\r\n\r\n    @Component.Builder\r\n    interface Builder{\r\n        Builder setLifecycleModule(LifecycleModule module);\r\n        MyDatabindingComponent build();\r\n    }\r\n}\r\n<\/pre>\n<pre class=\"lang: decode:true \">@Module\r\npublic class LifecycleModule {\r\n    private Lifecycle lifecycle;\r\n\r\n    public LifecycleModule(Lifecycle lifecycle) {\r\n        this.lifecycle = lifecycle;\r\n    }\r\n\r\n    @Provides\r\n    public ClickBinding provideClickBinding(){\r\n        return new ClickBindingImpl(lifecycle);\r\n    }\r\n}\r\n<\/pre>\n<p>\uc6b0\uc120 ClickBindingComponent\uc758 \uc774\ub984\uc744 MyDatabindingComponent\ub85c \ubc14\uafe8\ub2e4. \uadf8\ub9ac\uace0 @Component \uc560\ub178\ud14c\uc774\uc158\uc744 \ucd94\uac00\ud558\uace0, \ucef4\ud3ec\ub10c\ud2b8 \ubaa8\ub4c8\ub85c LifecycleModule\uc744 \uc0c8\ub85c \uc815\uc758\ud588\ub2e4.\u00a0<\/p>\n<p>DataBindingComponent \ud2b9\uc131\uc0c1 \ucef4\ud30c\uc77c \ud0c0\uc784\uc5d0 \ubaa8\ub4e0 DataBindingComponent\ub97c \uc0c1\uc18d\/\uad6c\ud604\ud55c \ubaa8\ubaa8\ub4e0 getter\uba54\uc11c\ub4dc\ub4e4\uc774 DataBindingComponent \uc778\ud130\ud398\uc774\uc2a4\ub0b4\uc5d0 \ubcd1\ud569\ub418\uae30 \ub54c\ubb38\uc5d0 DataBindingComponent\ub97c \ud558\ub098\uc758 \uc548\ub4dc\ub85c\uc774\ub4dc \ud504\ub85c\uc81d\ud2b8 \ubaa8\ub4c8\ub808\ubca8\uc5d0\uc11c \ubd84\ub9ac\ud574\uc11c \uc0ac\uc6a9\ud558\ub294\uac83\uc774 \ubd88\uac00\ub2a5\ud558\ub2e4. \uadf8\ub7ec\ubbc0\ub85c \ud2b9\uc815 \ud074\ub798\uc2a4(\uc5ec\uae30\uc5d0\uc11c\ub294 Lifecycle\uc774 \ud574\ub2f9)\uc5d0 \uc758\uc874\uc801\uc778 \ubc14\uc778\ub529\uc5b4\ub311\ud130\uc640 \uadf8\ub807\uc9c0 \uc54a\uc740 \ubc14\uc778\ub529\uc5b4\ub311\ud130\ub97c \ud568\uaed8 \uc0ac\uc6a9\ud558\uae30 \uc704\ud574 \uc774\ub97c Dagger2\uc758 \ubaa8\ub4c8\ub85c \ubd84\ub9ac\ud558\uace0, Dagger2 \ucef4\ud3ec\ub10c\ud2b8\uc758 Builder\ub97c \ud1b5\ud574 \uc120\ud0dd\uc801\uc73c\ub85c \uad6c\ud604\ud560 \uc218 \uc788\ub3c4\ub85d \ud588\ub2e4.<\/p>\n<p>Dagger2\uc758 \ucef4\ud3ec\ub10c\ud2b8\uc640 \ubaa8\ub4c8 \uad6c\ud604\uc774 \ub05d\ub0ac\ub2e4\uba74, \ucef4\ud30c\uc77c \ud0c0\uc784\uc5d0 DaggerMyDataBindingComponent\uac00 \uc0dd\uc131\ub418\uace0, \ub2e4\uc74c\uacfc \uac19\uc774 \uc0ac\uc6a9\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre class=\"lang: decode:true\">ActivityMainBinding binding = DataBindingUtil.setContentView(\r\n        this,\r\n        R.layout.activity_main,\r\n        DaggerMyDatabindingComponent.builder()\r\n                .setLifecycleModule(new LifecycleModule(getLifecycle()))\r\n                .build()\r\n);<\/pre>\n<p>\ubcf8\ubb38\uc758 \uc608\uc81c\ub294 <a href=\"https:\/\/github.com\/Charlezz\/DatabindingComponentSample\">github<\/a>\uc5d0\uc11c \ud655\uc778 \ud560 \uc218 \uc788\ub2e4.<\/p>\n<h3>\ub9c8\uce58\uba70<\/h3>\n<p>\ub370\uc774\ud130\ubc14\uc778\ub529\uacfc Dagger2\ub294 \uacb0\ud569\ub3c4\ub97c \ub290\uc2a8\ud558\uac8c \ub9cc\ub4e4\uc5b4\uc8fc\ub294 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc774\uba70 \ud568\uaed8 \uc0ac\uc6a9\ud558\uba74 \uc2dc\ub108\uc9c0\ud6a8\uacfc\uac00 \uc0dd\uae30\uae30 \ub54c\ubb38\uc5d0 \uc880 \ub354 \uc720\uc5f0\ud558\uace0 \uc7ac\uc0ac\uc6a9\uc131 \ubc0f \ud655\uc7a5\uc131\uc744 \uc99d\ub300\uc2dc\ucf1c\uc8fc\ub294 \ucf54\ub4dc\ub97c \ub9cc\ub4e4 \uc218 \uc788\ub2e4.\u00a0<\/p>\n<p><a href=\"https:\/\/www.charlezz.com\/wordpress\/wp-content\/uploads\/2019\/12\/4aac307b5254b0.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.charlezz.com\/wordpress\/wp-content\/uploads\/2019\/12\/4aac307b5254b0.jpg\" alt=\"\" width=\"500\" height=\"281\" class=\"aligncenter size-full wp-image-43836\" srcset=\"https:\/\/charlezz.com\/wordpress\/wp-content\/uploads\/2019\/12\/4aac307b5254b0.jpg 500w, https:\/\/charlezz.com\/wordpress\/wp-content\/uploads\/2019\/12\/4aac307b5254b0-300x169.jpg 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DataBindingComponent\uc640 Dagger2\uc640 \ud568\uaed8 \uc0ac\uc6a9\ud558\uae30 \uc774\ubc88\uc5d0 \ub2e4\ub8f0 \ub0b4\uc6a9\uc740 DatabindingComponent \uc0ac\uc6a9\ud558\uae30 2\ud0c4\uc73c\ub85c DataBindingComponent\ub97c \uc758\uc874\uc131 \uc8fc\uc785 \ud504\ub808\uc784\uc6cc\ud06c\uc778 Dagger2\uc640 \ud568\uaed8 \uc0ac\uc6a9\ud558\ub294 \ubc29\ubc95\uc5d0 \ub300\ud574\uc11c \uc54c\uc544\ubcf8\ub2e4. Prerequisite \ub370\uc774\ud130\ubc14\uc778\ub529 \ub77c\uc774\ube0c\ub7ec\ub9ac DatabindingComponent \uc0ac\uc6a9\ud558\uae30 Dagger2\ub97c \uc54c\uc544\ubcf4\uc790 DataBindingComponent \/w Dagger2 DataBindingComponent \uacf5\uc2dd \ubb38\uc11c\ub97c \ucc38\uc870\ud558\uba74, \ub2e4\uc74c\uacfc \uac19\uc740 \ub0b4\uc6a9\uc774 \uc788\ub2e4. If using Dagger 2, the developer should extend this interface and annotate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[16],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/43833"}],"collection":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=43833"}],"version-history":[{"count":6,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/43833\/revisions"}],"predecessor-version":[{"id":43842,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/43833\/revisions\/43842"}],"wp:attachment":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=43833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=43833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=43833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}