Skip to content

[Feat] navigation 2.x scope#2309

Merged
arnaudgiuliani merged 5 commits into4.2.0from
feat_navigation_scope
Nov 18, 2025
Merged

[Feat] navigation 2.x scope#2309
arnaudgiuliani merged 5 commits into4.2.0from
feat_navigation_scope

Conversation

@arnaudgiuliani
Copy link
Copy Markdown
Member

@arnaudgiuliani arnaudgiuliani commented Nov 14, 2025

Add Navigation Scope Support for Compose Navigation

Introduces navigation scope support for Koin with Jetpack Compose Navigation, enabling automatic scope management tied to NavBackStackEntry lifecycle.

Features

  • KoinNavigationScope composable - Creates and manages a Koin scope bound to a NavBackStackEntry, with automatic cleanup on navigation away
  • navigationScope DSL - Module DSL for defining navigation-scoped dependencies, following the same pattern as activityScope and fragmentScope

Usage

  module {
      navigationScope {
          scoped { MyRepository() }
      }
  }

  @Composable
  fun MyScreen() {
      NavHost(navController = navController, startDestination = ListDestination) {
                composable<ListDestination> { backStackEntry -> 
                   KoinNavigationScope(backStackEntry) {
                  val repository = koinInject<MyRepository>()
                  //...
                 }
  }

Implementation

  • Scope ID derived from NavBackStackEntry.id
  • Cleanup on onAbandoned() only (proper lifecycle management)
  • Marked @KoinExperimentalAPI

@arnaudgiuliani arnaudgiuliani added this to the 4.2.0 milestone Nov 14, 2025
@arnaudgiuliani arnaudgiuliani merged commit 33c455d into 4.2.0 Nov 18, 2025
3 of 4 checks passed
@arnaudgiuliani arnaudgiuliani deleted the feat_navigation_scope branch November 18, 2025 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant