Summit Session: A nifty solution for compile time dependency injection

1 view
Skip to first unread message

Christopher Vogt

unread,
Sep 3, 2014, 4:32:14 PM9/3/14
to Scala...@googlegroups.com
There is runtime dependency injection like Spring or Guice. And there are well known methods for compile time dependency injection like global imports, passing values into methods and constructors explicitly or implicitly, multiple inheritance or the cake pattern.

I recently discovered a new one. I came up with an encoding of a type-safe, type-indexed map in Scala, which I call TMap. Passing it through your functions as a single context object leads to a neat way of doing dependency injection. Using the for-expression syntax even saves you from having to pass it along explicitly. A series of code examples refactoring regular argument passing step-by-step to a TMap dependency context can be found here and above: https://github.com/cvogt/slick-action/blob/master/src/test/scala/org/cvogt/di/TMapTest.scala#L215

I'd like to present this new approach to dependency injection, speak about potential weaknesses and generally discuss the approach.
Reply all
Reply to author
Forward
0 new messages