How would one do dependency injection in scala?

前端 未结 9 1621
鱼传尺愫
鱼传尺愫 2021-01-30 12:25

I\'m still at the beginning in learning scala in addition to java and i didn\'t get it how is one supposed to do DI there? can or should i use an existing DI library, should it

9条回答
  •  北恋
    北恋 (楼主)
    2021-01-30 13:09

    Dependency Injection itself can be done without any tool, framework or container support. You only need to remove news from your code and move them to constructors. The one tedious part that remains is wiring the objects at "the end of the world", where containers help a lot.

    Though with Scala's 2.10 macros, you can generate the wiring code at compile-time and have auto-wiring and type-safety.

    See the Dependency Injection in Scala Guide

提交回复
热议问题