distage is a pragmatic module system for Scala and Scala.js. It combines the simplicity and expressiveness of pure FP with the flexibility and extreme late-binding, traditionally associated with Java dependency injection frameworks, such as Guice.
The best way get started is to clone
distage-example sample project and play around with it.
It shows how to write an idiomatic
distage application from scratch and how to:
- write tests using
- setup portable test environments using
- create role-based applications
- enable compile-time checks for fast feedback on wiring errors
Faster applications and tests:
distageguarantees that no unnecessary instantiations will happen during your tests or application startup.
distageitself is very fast, in part due to not using Java reflection.
Faster integration tests: distage-testkit allows you to reuse expensive resources (such as database connections and docker containers) across multiple test suites, gaining performance without sacrificing correctness.
Managed test environments: distage-testkit eliminates all the hard work of setting up test environments, especially configurable ones. Easily describe tests environments, share heavy resources across all the test suites in the environment, use the power of DI to override components and run your tests under different scenarios.
Compile-time error detection:
distagecan detect wiring errors at compile-time for fast feedback during development. Despite that,
distageextensions are simple to write and do not require type-level programming.
Early failure detection:
distageperforms all the integration checks for your application and tests even before any instantiations happen.
Simplify development workflow: distage-framework allows you to develop Role-based applications, letting you run all your services in one process for development purposes (and even switch to mock implementations with a single commandline argument).
Easy deployment: Role-based applications allow you to deploy and orchestrate fewer containers and achieve a higher computation density.
distageprovides you insights about your application structure and allows you to introspect and modify it on the fly, before any instantiations happen.
distagesupports resources and lifecycle natively and guarantees proper cleanups even when something went wrong.
distageis designed to not impact the way your Scala code is written, it just removes all the initialization boilerplate. You don’t need to learn magic tricks to write components in a distage application.
distageis available for JVM, Graal Native Image and Scala.js.
Given its native support for type classes and higher-kinded types – both features indispensable to functional programming – distage is one of the leading dependency injection libraries out there. Bonus points for being built by a wicked-smart team that contributes to ZIO!
— John A. De Goes
Q: How to pronounce
Q: How do I switch between production and test implementations of components?
A: Use Activation Axis
- Advanced Features
- Syntax Reference
- Izumi 1.0: Your Next Scala Stack
- Scala, Functional Programming and Team Productivity
- Hyper-pragmatic Pure FP Testing with distage-testkit
- Livecoding: DIStage & Bifunctor Tagless Final
- DevInsideYou — Tagless Final with BIO