Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dependency Injection in Scala

Yuki Ishikawa
December 06, 2017

Dependency Injection in Scala

青山エンジニア勉強交流会~Scala勉強会~ (2017/12/04)
「DIとは何か」について軽く説明した後、ScalaのDI手法を4つ(Manual DI, Cake Pattern, MacWire, Guice)紹介しました

Yuki Ishikawa

December 06, 2017
Tweet

More Decks by Yuki Ishikawa

Other Decks in Technology

Transcript

  1. Profile • ϑΝϯίϛೖࣾ4೥໨ • Scalaྺ2೥൒͘Β͍ (લ: Java, Ruby, Perl,PHP, etc.)

    • nend, nex8, viidleͷ഑৴γεςϜߏஙΛ୲౰ • ࠷ۙ͸ϒϩοΫνΣʔϯͷษڧΛͨ͠Γ ੴ઒ ༟थ Yuki Ishikawa
  2. "E$POUSPMMFS "E4FSWJDF "E4FSWJDF*NQM Dependency Injection (DI) ͱ͸Կ͔ʁ .PEVMF *OKFDUPS AdController:

    ޿ࠂϦΫΤετͷϋϯυϦϯά AdService: ࠷దͳ޿ࠂͷબग़ϩδοΫ
  3. • MacWire • Guice • Spring • Scaldi • SubCut

    • Freestyle
 (Free Monad & Taggless Final) Pure Scala Library • Manual DI • Cake Pattern • Reader Monad • Free Monad • Tagless Final ScalaͷDIύλʔϯ
  4. Manual DI (Constructor Injection) Pros Cons • Ұ൪खܰʹ࢝ΊΒΕΔํ๏ • Compile-time

    DI • Pure Scala • ґଘؔ܎͕ଟ͍ͱ഑ઢ࡞ۀ͕ͭΒ͍ খن໛ͷϓϩδΣΫτͳΒManualͰे෼!!
  5. Cake Pattern Pros Cons • Compile-time DI • Pure Scala

    • େྔͷϘΠϥʔϓϨʔτ • ॊೈੑ͕௿͍ ‣ Component͕ΠϯελϯεΛ͔̍ͭ࣋ͯ͠ͳ͍ͷͰɺ2ͭͷಉ͡ ܕʹґଘͰ͖ͳ͍ • ύϑΥʔϚϯεɾίϯύΠϧ࣌ؒʹѱӨڹʁ(ະݕূ)