Create CoreModule.kt — the network graph in one module
In the code column — core/di/CoreModule.kt. It's the same network you built by hand in lesson 5 (object Network), now expressed as Koin recipes. single<Retrofit> uses get<Json>() — Koin hands it the Json defined just above. single<PicaApi> asks for get<Retrofit>(). The graph assembles itself.
Now — feature modules. Each feature (menu, cart) gets its own module next to its code.
// feature/menu/di/MenuModule.kt
val menuModule = module {
single { MenuRepository(get()) } // get() = PicaApi (from coreModule)
viewModel { MenuViewModel(get()) } // get() = MenuRepository
}
// feature/cart/di/CartModule.kt — the cart is still the in-memory MVI from lesson 3
val cartModule = module {
viewModel { CartViewModel() } // no dependencies yet;
// OrderRepository/TableSession arrive in lessons 9/10
}
Notice: MenuViewModel didn't change — it still takes MenuRepository in its constructor, exactly as before. The only thing that changed is who builds it: no longer you by hand, but Koin via get().
Tip.
singlevsfactory:Retrofit,PicaApi, repositories — make themsingle(one copy for the whole app; expensive to rebuild). A ViewModel is alwaysviewModel { }— its lifecycle is owned by the screen.