# Custom Scopes in Koin: A Practical Example

DevFeed: [Custom Scopes in Koin: A Practical Example](<https://devfeed.tech/articles/custom-scopes-in-koin-a-practical-example-22968.md>)

Original publisher: [Read original article](<https://blog.insert-koin.io/custom-scopes-in-koin-a-practical-example-79cc1188810f?source=rss----925561f2ecdf---4>)

Author: Gabriel Bronzatti Moro

Published: 2026-06-19T12:01:01Z

Content type: tutorial

Language: en

Sources: [Koin developers - Medium](<https://devfeed.tech/sources/koin-developers-medium.md>)

Topics: [App](<https://devfeed.tech/topics/app.md>), [Open Source](<https://devfeed.tech/topics/open-source.md>), [Mobile](<https://devfeed.tech/topics/mobile.md>)

Tags: [app](<https://devfeed.tech/tags/app.md>), [components](<https://devfeed.tech/tags/components.md>), [compose-multiplatform](<https://devfeed.tech/tags/compose-multiplatform.md>), [data](<https://devfeed.tech/tags/data.md>), [dependency](<https://devfeed.tech/tags/dependency.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [koin](<https://devfeed.tech/tags/koin.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [project](<https://devfeed.tech/tags/project.md>), [scopes](<https://devfeed.tech/tags/scopes.md>), [state](<https://devfeed.tech/tags/state.md>), [stateless](<https://devfeed.tech/tags/stateless.md>), [user-experience](<https://devfeed.tech/tags/user-experience.md>)

## AI overview

A practical tutorial on using custom scopes in Koin to keep a selected user profile image available across an application. It demonstrates a session scope, session data, and a stateless session manager using StreamPlayerApp as the example.

## Source excerpt

Hey friends 👋 Today, we are going to explore how we can create a custom scope, one of the powerful features provided by Koin. To make things practical 🔨, we'll walk through a real-world use case from the open-source project StreamPlayerApp (created by CodandoTV). Wireframes of a mobile app -- Unsplash by @alvarordesignWhat is the problem? StreamPlayerApp is an open-source project that aims to recreate the core experience of Netflix. One of its features allows users to select a profile, similar to the profile selection screen found in streaming platforms. The selected profile image needs to be accessible across the entire application, ensuring a consistent user experience on every screen. Whenever a user changes their profile, the updated image should be immediately reflected throughout the app, allowing all screens to stay synchronized with the current profile selection. Screenshots demonstrating the user profile selection feature.How we solve this problem using Custom Scopes? First, we create a class that represents the scope of a user session: class SessionScope Next, we create a lightweight data class containing only the information that needs to be kept in memory throughout the user session: data class UserSessionInfo( // represents the time user changed the profile val userTimestamp: Instant, // represents the selected picture url val profileImageUrl: String ) We then created a dedicated class responsible for managing the user's session lifecycle and state. class SessionManager { private val scopeId: String = "user_session" /** * Create custom scope and hold the user's session data */ fun openSession(imageUrl: String) { closeSession() val koin = KoinPlatform.getKoin() val scope = koin.createScope<SessionScope>( scopeId = scopeId, ) scope.declare( UserSessionInfo( userTimestamp = Clock.System.now(), profileImageUrl = imageUrl ) ) } /** * Retrieve the current user session */ fun userSessionInfo(): UserSessionInfo? { return KoinPlatform.getKoin() .getScopeOrNull(sc