You are currently viewing When to use context receiver?

When to use context receiver?

So I was reading the KEEP on context receivers, https://github.com/Kotlin/KEEP/blob/context-receivers/proposals/context-receivers.md#unified-context-properties

And I’m having a hard time understanding when they should be used. For things like coroutines and composables it makes sense to me since calling a suspend function outside of a coroutine just doesn’t make sense, but the example used with the logger doesn’t make a tone of sense to me because I don’t see much value in marking methods based on if they access to a logger or not.

Adding onto this, would it make sense to handle dependency injection this way? E.g. instead of injecting a repo into a ViewModel would it be better to make it available via context receiver?

submitted by /u/TheAmpca
[link] [comments]