Question regarding Ktor’s DI container - is there ...
# ktor
k
Question regarding Ktor’s DI container - is there a way to scope the dependencies or are they singletons by default only?
b
It's currently just singletons tied to the
Application
instance. What kind of scope were you looking for?
k
I was looking to inject dependencies based on request (on params/authenticated user)
b
Hmm you're not the first to ask about request-scoped dependencies, though we avoided introducing them because it's a bit heavy-weight for requests and could create some overhead. Generally, you can go with extension functions / values or attributes on requests, or you can use some cache scoped to user ID or whatever input defines the instance.
k
yeah, I will work around it, I was just curious if there's something already there
b
we should probably provide some official guidance there, I'll start looking into it 🤔
k
that'd be awesome, thanks 🙏