u/danielciocirlanin r/scala • Recommends
Automatic Dependency Injection in Pure Scala
#dependencyinjection#scala3#givens
27K subscribers • 59 videos on Hallway
Advanced. Deep dive for people who know the field.
5K views2 years ago1 recommendation
Programming languagesSoftware designScalaDesign patterns
How to implement automatic dependency injection in pure Scala 3 using givens, match types, and type-level programming without external libraries.
GitHub: github.com/scala/scala3/blob/main/tests/run/Providers.scala Learn ZIO: rockthejvm.com/p/zio In this video we will demonstrate a technique for automatic dependency injection in pure Scala with no other libraries or frameworks. Here, instances are passed automatically just by the structure of the types in question, without relying on macros, annotations, reflection or any runtime behavior. The technique is based on an example from Martin Odersky after an informal discussion (shared with his permission). We'll cover - a scenario where dependency injection is useful - how explicit dependency injection is done - how the ZIO library manages dependency injection with ZLayers - how we can use givens, match types and a minimum of type-level programming to make the compiler automatically infer which instances need to be injected in which place Follow Rock the JVM on: LinkedIn: linkedin.com/company/rockthejvm X: x.com/rockthejvm Blog: blog.rockthejvm.com ------------------------------------------------------------------------- Home: rockthejvm.com -------------------------------------------------------------------------What people say. Recommended as an elegant demonstration of using Scala 3's type system for dependency injection.
u/danielciocirlanin r/scala • Recommends