
Dependency Injection Beyond Basics: Stop Letting Hilt Modules Become Code Smells
What We Will Build In this workshop, we will take a bloated Hilt module — the kind hiding in every mid-sized Android project — and refactor it step by step. By the end, you will have a clean, split module structure, a unit test that needs zero framework boilerplate, and a working kotlin-inject component ready for Kotlin Multiplatform. Let me show you a pattern I use in every project. Prerequisites An Android project using Hilt (or familiarity with it) Kotlin 1.9+ and KSP configured in your build Basic understanding of constructor injection Step 1: Audit the Monolith Module Open your biggest Hilt module. If it looks anything like this, we have work to do: @Module @InstallIn ( SingletonComponent :: class ) object NetworkModule { @Provides @Singleton fun provideOkHttpClient (): OkHttpClient { /* ... */ } @Provides @Singleton fun provideRetrofit ( client : OkHttpClient ): Retrofit { /* ... */ } @Provides @Singleton fun provideUserApi ( retrofit : Retrofit ): UserApi { /* ... */ } @Provides
Continue reading on Dev.to Webdev
Opens in a new tab




