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

ゼロから理解するDependency Injection / Understanding Dependency Injection from the Ground Up

rockname
October 27, 2023

ゼロから理解するDependency Injection / Understanding Dependency Injection from the Ground Up

rockname

October 27, 2023
Tweet

More Decks by rockname

Other Decks in Technology

Transcript

  1. θϩ͔Βཧղ͢Δ

    %FQFOEFODZ*OKFDUJPO

    !J045FTU/JHIU
    SPDLOBNF

    View full-size slide


  2. 4NBSU#BOL *OD
    .PCJMF"QQMJDBUJPO%FWFMPQFS
    ϩΫωϜ
    !@SPDLOBNF
    ࣗݾ঺հ
    !SPDLOBNF

    View full-size slide


  3. %FQFOEFODZ*OKFDUJPO
    %*$POUBJOFSͷجຊ
    %BHHFSʹֶͿґଘͷϥΠϑλΠϜ؅ཧ
    4XJGU6*ΞϓϦʹ͓͚Δ%*$POUBJOFSͷ࣮૷ྫ
    ຊ೔͓࿩͢͠Δ͜ͱ

    View full-size slide

  4. %FQFOEFODZ*OKFDUJPO

    View full-size slide


  5. %FQFOEFODZ*OKFDUJPO
    w ྫϩάΠϯϑϩʔ
    IUUQTEFWFMPQFSBOESPJEDPNUPQJDBSDIJUFDUVSF

    View full-size slide


  6. %FQFOEFODZ*OKFDUJPO

    View full-size slide

  7. ґଘΛ಺෦ͰॳظԽ͢Δॻ͖ํ

    View full-size slide


  8. %FQFOEFODZ*OKFDUJPO
    w ςετ࣌ʹ"1*ϦΫΤετ͕ඈΜͰ͠·͍ɺ࣮ߦ݁Ռ͕ෆ҆ఆʹͳ
    Δɻ"1*ϦΫΤετ෦෼Λελϒʹஔ͖׵࣮͑ͯߦ͍ͨ͠
    w σϞΞϓϦ࣌ʹ͸ຊ൪σʔλΛࢀরͤͣʹɺσϞ༻ͷσʔλΛฦ͢
    Α͏ʹ࣮૷Λࠩ͠ସ͍͑ͨ
    ՝୊ςετ΍σϞΞϓϦ࣮ߦ࣌ʹґଘΛஔ͖׵͑ΒΕͳ͍

    View full-size slide


  9. %FQFOEFODZ*OKFDUJPO
    w ্ҐϞδϡʔϧ͸͍͔ͳΔ΋ͷ΋ԼҐϞδϡʔϧ͔Β࣋ͪࠐΜͰ͸
    ͳΒͳ͍ɻ૒ํͱ΋ந৅ʢྫͱͯ͠ΠϯλʔϑΣʔεʣʹґଘ͢Δ
    ΂͖Ͱ͋Δ
    w ந৅͸ৄࡉʹґଘͯ͠͸ͳΒͳ͍ɻৄࡉʢ۩৅తͳ࣮૷಺༰ʣ͕ந
    ৅ʹґଘ͢Δ΂͖Ͱ͋Δ
    ґଘੑٯసͷݪଇ
    IUUQTKBXJLJQFEJBPSHXJLJґଘੑٯసͷݪଇ

    View full-size slide

  10. ґଘੑٯసͷݪଇʹैͬͨॻ͖ํ

    View full-size slide


  11. %FQFOEFODZ*OKFDUJPO

    View full-size slide


  12. %FQFOEFODZ*OKFDUJPO

    View full-size slide


  13. %FQFOEFODZ*OKFDUJPO
    ந৅ʹରͯ͠ґଘ͢ΔΑ͏ʹ֎͔Β
    ࣮૷Λ஫ೖ͢ΔύλʔϯΛɺґଘੑ
    ͷ஫ೖɺ%FQFOEFODZ*OKFDUJPO
    %*
    ͱݺͿ

    View full-size slide

  14. %*$POUBJOFSͷجຊ

    View full-size slide


  15. %*$POUBJOFSͷجຊ
    w ίʔυͷෳ਺ՕॴͰ"VUI3FQPTJUPSZΛॳظԽ͢Δ৔߹͸ɺίʔυ
    ͕ॏෳͯ͠͠·͏
    w ෳ਺ਓͰ։ൃ͢Δࡍʹɺґଘ͕૿͑Δͨͼʹमਖ਼͢Δඞཁͷ͋Δ
    ϑΝΠϧ਺͕૿͑ɺίϯϑϦΫτͷൃੜ཰͕ߴ·Δ
    w ґଘؔ܎͸ॱ൪ʹએݴ͢Δඞཁ͕͋Δɻ࡞੒͢Δʹ
    ͸ɺ-PHJO7JFX.PEFMͷલʹ"VUI3FQPTJUPSZΛॳظԽ͢Δඞཁ
    ͕͋Δ
    ՝୊ᶃϘΠϥʔϓϨʔτίʔυ͕ଟ͍

    View full-size slide


  16. %*$POUBJOFSͷجຊ
    w ΋͠ෳ਺ͷػೳͰ"VUI3FQPTJUPSZͷΠϯελϯεΛ࠶ར༻͢Δ
    ৔߹͸ɺγϯάϧτϯύλʔϯʹै͏ඞཁ͕͋Δɻ͢΂ͯͷςε
    τ͕ಉ͡γϯάϧτϯΠϯελϯεΛڞ༗͢ΔͨΊɺγϯάϧτ
    ϯύλʔϯʹΑΓςετ͸ΑΓࠔ೉ʹͳΔ
    ՝୊ᶄΠϯελϯεͷ࠶ར༻͕ࠔ೉

    View full-size slide


  17. %*$POUBJOFSͷجຊ
    ొ࿥͞ΕͨґଘΛฦͯ͘͠ΕΔίϯςφΫϥε
    %*$POUBJOFS

    View full-size slide

  18. %BHHFSʹֶͿґଘͷϥΠϑλΠϜ؅ཧ

    View full-size slide


  19. %BHHFSʹֶͿґଘͷϥΠϑλΠϜ؅ཧ
    w ࠶ར༻͍ͨ͠ґଘͷϥΠϑλΠϜ͸ΞϓϦέʔγϣϯͷϥΠϑλ
    ΠϜͱඞͣ͠΋ಉ͡ͱ͸ݶΒͳ͍
    w Ϣʔβʔ͕ϩάΠϯ͍ͯ͠ΔؒͷΈʹ࠶ར༻͍ͨ͠ґଘ΍ɺෳ਺
    ΞΧ΢ϯτΛ੾Γସ͑ͨλΠϛϯάͰഁغ͍ͨ͠ґଘ΋͋Δ

    View full-size slide


  20. %BHHFSʹֶͿґଘͷϥΠϑλΠϜ؅ཧ
    "OESPJEͷΞϓϦΛ։ൃ͢Δ্Ͱґଘؔ܎ͷ஫ೖΛαϙʔτ͢Δ

    %*$POUBJOFSͷϥΠϒϥϦ
    %BHHFS

    View full-size slide


  21. %BHHFSʹֶͿґଘͷϥΠϑλΠϜ؅ཧ

    View full-size slide


  22. %BHHFSʹֶͿґଘͷϥΠϑλΠϜ؅ཧ
    ྫ4MBDLͷ"OESPJEΞϓϦ
    IUUQTTMBDLFOHJOFFSJOHFYUFOEJOHBOWJMGPSGVOBOEQSPGJU

    View full-size slide

  23. 4XJGU6*ΞϓϦʹ͓͚Δ%*$POUBJOFSͷ࣮૷ྫ

    View full-size slide


  24. 4XJGU6*ΞϓϦʹ͓͚Δ%*$POUBJOFSͷ࣮૷ྫ
    w 4XJGU6*͸એݴత6*ϑϨʔϜϫʔΫͰ͋Δ
    w એݴ͞Εͨ7JFXʹ͸਌ࢠؔ܎͕͋ΓɺπϦʔߏ଄͕ੜ·ΕΔ
    w 7JFXͷπϦʔߏ଄ͱ$PNQPOFOUͷπϦʔߏ଄ΛରԠ͚ͮΔ͜ͱ
    ͰɺґଘͷϥΠϑλΠϜΛ؅ཧ͢Δ͜ͱ͕Մೳ

    View full-size slide


  25. 4XJGU6*ΞϓϦʹ͓͚Δ%*$POUBJOFSͷ࣮૷ྫ
    w ྫෳ਺ΞΧ΢ϯτʹରԠͨ͠4/4ΞϓϦ

    View full-size slide


  26. 4XJGU6*ΞϓϦʹ͓͚Δ%*$POUBJOFSͷ࣮૷ྫ

    View full-size slide

  27. %*$POUBJOFSͷ࣮૷

    View full-size slide

  28. 7JFXଆͷ࣮૷

    View full-size slide


  29. ·ͱΊ
    w %FQFOEFODZ*OKFDUJPO͸ɺந৅ʹର࣮ͯ͠૷͕ґଘ͢ΔΑ͏ʹઃ
    ܭ͢ΔͨΊͷύλʔϯͰ͋Γɺςετ࣌ͳͲʹ࣮૷Λஔ͖׵͑Δ
    ͜ͱΛՄೳʹ͢Δ
    w %*$POUBJOFS͸ɺొ࿥͞ΕͨґଘΛฦͯ͘͠ΕΔίϯςφΫϥε
    Ͱ͋ΓɺґଘΛ૊ΈཱͯΔͨΊͷϘΠϥʔϓϨʔτͷ࡟ݮͱɺϥ
    ΠϑλΠϜ͝ͱͷΠϯελϯεͷ࠶ར༻ΛՄೳʹ͢Δ

    View full-size slide

  30. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ

    View full-size slide