
๐์ฐธ๊ณ ์๋ฃ
@InstallIn annotation๋ก Hilt Component ์ง์
-> ๊ฐ Component์ ๋์๋๋ Android class์ ์ข
์์ฑ ์ฃผ์
| Hilt Component | Injector for (Android class) |
|---|---|
| SingletonComponent | Application |
| ActivityRetainedComponent | N/A |
| ViewModelComponent | ViewModel |
| ActivityComponent | Activity |
| FragmentComponent | Fragment |
| ViewComponent | View |
| ViewWithFragmentComponent | View annotated with @WithFragmentBindings |
| ServiceComponent | Service |
Hilt๋ ๋์๋๋ Android class์ ์๋ช ์ฃผ๊ธฐ์ ๋ง์ถฐ Component created/destroyed
Hilt์ binding์ ๊ธฐ๋ณธ์ ์ผ๋ก unscoped
-> binding ์์ฒญ๋ ๋๋ง๋ค, ํ์ํ ํ์
์ ์ธ์คํด์ค ์๋ก ์์ฑ
Scope annotation์ผ๋ก scope ์ง์ ๊ฐ๋ฅ
-> ํด๋น scope ๋ด์์๋, ์๋ก์ด ์ธ์คํด์ค ์์ฑ X, ๊ฐ์ ์ธ์คํด์ค ๊ณต์
| Android class | Hilt Component | Scope |
|---|---|---|
| Application | SingletonComponent | @Singleton |
| Activity | ActivityRetainedComponent | @ActivityRetainedScoped |
| ViewModel | ViewModelComponent | @ViewModelScoped |
| Activity | ActivityComponent | @ActivityScoped |
| Fragment | FragmentComponent | @FragmentScoped |
| View | ViewComponent | @ViewScoped |
| View annotated with @WithFragmentBindings | ViewWithFragmentComponent | @ViewScoped |
| Service | ServiceComponent | @ServiceScoped |
Hilt Component์ binding์ scoping
-> Component destroyed ๋ ๋๊น์ง binding ๋ฉ๋ชจ๋ฆฌ์ ์ ์งํด์ผ
-> ๋น์ฉ ํผ!

@AndroidEntryPoint ์ ๋
ธํ
์ด์
๊ณผ ํจ๊ป @WithFragmentBindings ์ ๋
ธํ
์ด์
ํ์