That’s a good question, and probably one deserving a separate blog with code examples.

One possibility is to use proxies (see for example — there’s nothing in the proxy usage that would require using a IoC container.

Another is to make the per-session or per-request “scoping” explicit by passing e.g. a SessionId => MyBean function instead of a MyBean instance. It’s less “magical” than what we know from web frameworks, but also much less surprising in usage. It‘s also crystal clear then which code actually touches sessions (even indirectly).

Scala software engineer, Functional Programming enthusiast, SoftwareMill co-founder

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store