I’m using Koin annotations with the compile time c...
# koin
b
I’m using Koin annotations with the compile time checks on, how can I provide an instance for a scope at runtime? I have a pretty standard object you would get at runtime (A user profile) that I want to provide for a LoggedInScope. Is that something I can do with Koin annotations?
I finally figured out how to provide an isntance with Koin Annotations with the compile time checks on. It’s not super pretty but it helps keep the compile time checking for everything else that is already provided 1. Create your scope and declare the instance
Copy code
val instance: MyClass = TODO()

getKoin().createScope<MyScope>()
  .apply {
    declare(instance)
  }
2. Make a function to mark it as provided
Copy code
@Scope(MyScope::class)
fun myInstance(@ScopeId(MyScope::class) instance: MyClass): MyClass = instance
3. Get that instance like normal
Copy code
@Scope(MyScope::class)
class AnotherClass(instance: MyClass)
1
a
👍