Lightweight Scala Dependency Injection Library
Scaldi provides simple and elegant way to do dependency injection in Scala. By using expressive power of the Scala language it defines intuitive and idiomatic DSL for binding and injecting dependencies. It is very extensible library, so you can easily extend or customize almost any aspect of it. Some of the more unique Scaldi features are advanced module composition and conditional bindings which definitely will help you build all kinds of applications - from small command-line tools to big non-trivial web applications. Not to mention Scaldi also nicely integrates with Akka and Play.
Read the documentation and learn how you can use scaldi in your project.
Have any ideas or questions? There are many places where you can share and discuss them with others.
If you like the project and want to contribute, then there are plenty ways to do so. Any ideas, improvements or bugfixes are very welcome! Just fork it now and start implementing new cool stuff :)
Scaldi also comes with the play framework support. Start using scaldi in a play application is as simple as configuring application loader and modules in application.conf:
Play now uses scaldi for dependency injection. From now on you can use scaldi to inject/bind bindings in your controllers as classes:
Learn more about play integrationYou can easily split bindings between different modules and then compose them together
Learn more about compositionScaldi provides an injected macro, which will inject all constructor arguments for you:
You can even override injection mechanism on argument level:
Learn more about constructor injectionYou can override bindings in order to mock parts of the application
Learn more about testingBindings may have conditions associated with them
and it's pretty straightforward to define new conditions
Learn more about conditionsYou can bind things like functions, lists or maps
and then inject them
For seamless integration with other libraries or existing codebase.
Learn more about JSR 330 supportExtend almost any part of the library, including
Some parts of the library are implemented as a type classes
With scaldi-akka you can inject ActorRefs and Props with injectActorProps and injectActorRef. Actors themselves can be defined in scaldi module.
Learn more about akka integrationJust include scaldi dependency in the SBT build and you are ready to go:
If you want to include scaldi into the play application, then scaldi-play would probably be more suitable for you
Then you can just define application loader and your modules in the application.conf like this:
Play 2.3.x is still supported, you just need to use scaldi-play-23 instead:
For the akka applications, scaldi-akka is the way to go:
If you are integrating or migrating existing apps that use JSR 330 annotations, then scaldi-jsr330 is the right choice:
After the initial setup you can read some documentation or look at scaldi presentation slides.
If you prefer more hands-on approach, then you may be interested in two example projects which you can play with: