[{"data":1,"prerenderedAt":69},["ShallowReactive",2],{"term-d\u002Fdependency-injection":3,"related-d\u002Fdependency-injection":57},{"id":4,"title":5,"acronym":6,"body":7,"category":39,"description":40,"difficulty":41,"extension":42,"letter":43,"meta":44,"navigation":45,"path":46,"related":47,"seo":51,"sitemap":52,"stem":55,"subcategory":6,"__hash__":56},"terms\u002Fterms\u002Fd\u002Fdependency-injection.md","Dependency Injection",null,{"type":8,"value":9,"toc":32},"minimark",[10,15,19,23,26,30],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 — The Vibe Check",[16,17,18],"p",{},"Instead of your UserService creating its own DatabaseConnection (tight coupling), you pass the database in from outside: new UserService(db). Now in tests you pass in a fake database, and in production you pass the real one. Your service does not know where the database came from. That is dependency injection. Simple idea, huge consequences.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"undefined",[11,27,29],{"id":28},"when-youll-hear-this","When You'll Hear This",[16,31,25],{},{"title":33,"searchDepth":34,"depth":34,"links":35},"",2,[36,37,38],{"id":13,"depth":34,"text":14},{"id":21,"depth":34,"text":22},{"id":28,"depth":34,"text":29},"architecture","Instead of your UserService creating its own DatabaseConnection (tight coupling), you pass the database in from outside: new UserService(db).","intermediate","md","d",{},true,"\u002Fterms\u002Fd\u002Fdependency-injection",[48,49,50],"Factory Pattern","Singleton Pattern","Inversion of Control",{"title":5,"description":40},{"changefreq":53,"priority":54},"weekly",0.7,"terms\u002Fd\u002Fdependency-injection","12xVl72JTPEQxG0GRSzT-9JNhUBBELFwkAC6JOi8uxA",[58,61,65],{"title":48,"path":59,"acronym":6,"category":39,"difficulty":41,"description":60},"\u002Fterms\u002Ff\u002Ffactory-pattern","You want to create a 'notification' object but it might be an EmailNotification, SMSNotification, or PushNotification depending on user preferences.",{"title":50,"path":62,"acronym":63,"category":39,"difficulty":41,"description":64},"\u002Fterms\u002Fi\u002Finversion-of-control","IoC","Inversion of Control is when a framework calls YOUR code instead of you calling the framework. You don't control the flow anymore — the framework does.",{"title":49,"path":66,"acronym":6,"category":39,"difficulty":67,"description":68},"\u002Fterms\u002Fs\u002Fsingleton-pattern","beginner","Singleton says: 'this class shall have exactly ONE instance, ever.' Database connections, config objects, loggers — things you only want created once.",1776518273638]