First part of the presentation about dependency injection in Scala from January's meetup of the Czech Scala Enthusiasts.
This part addresses usage of Java DI frameworks in Scala (CDI, Spring, Guice) and SubCut (pure Scala library).
Spring Scala project● developed by SpringSource● targets Spring 3.2● work in progres (1.0.0.M1)● wiring beans using functional syntax● functional wrappers for Spring templates ○ functions instead of anonymous callbacks
Scopes cont.● in CDI, only singleton and dependent are injected as direct references ○ different lifecycles, serialization● DI framework will inject a proxy instead ○ thread-local magic
Proxies● restrictions on the proxied class ○ might vary between DI frameworks● needs a default constructor● cannot be final or have final methods
Proxy problems● Scala compiler emits final methods ○ even if there are none in the source code● access to a private val from a closure● such class is "unproxyable"
Java DI Frameworks Summary● you can use them if you want ○ Spring is not just DI
Java DI Frameworks Summary● maybe with some additional wrappers to make them more Scala-friendly
Java DI Frameworks Summary● problems may arise if there are additional restrictions on classes (setters, proxies, ...) ○ these can be avoided with some effort
SubCut"Scala Uniquely Bound Classes Under Traits" https://github.com/dickwall/subcut● very small and simple DI library● pure and idiomatic Scala● binding DSL● uses implicits to cut down on boilerplate JavaPosse ScalaWags