<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-dependency-injection-works-in-nestjs-htekyk7qh" -->

---
title: How Dependency Injection Works in NestJS | daily.dev
description: A brief explainer on how dependency injection works in NestJS, using a pizza chef analogy to illustrate tight coupling vs. injected dependencies. Shows why...
canonical: https://daily.dev/posts/how-dependency-injection-works-in-nestjs-htekyk7qh
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How Dependency Injection Works in NestJS | daily.dev
og:description: A brief explainer on how dependency injection works in NestJS, using a pizza chef analogy to illustrate tight coupling vs. injected dependencies. Shows why...
og:url: https://daily.dev/posts/how-dependency-injection-works-in-nestjs-htekyk7qh
og:image: https://api.daily.dev/og/posts/hTEKYK7Qh.png
og:image:alt: How Dependency Injection Works in NestJS
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How Dependency Injection Works in NestJS

**[JavaScript Mastery](https://daily.dev/sources/javascriptmastery)** · 1 min read · 16 upvotes · 4 comments

## Summary

A brief explainer on how dependency injection works in NestJS, using a pizza chef analogy to illustrate tight coupling vs. injected dependencies. Shows why manually instantiating services inside methods is problematic and how NestJS modules handle service registration and injection correctly.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=4BzJ13ZSDPY>

## Community discussion

Top comments from developers on daily.dev.

**@projekcomm** · 2 upvotes

> LOL! The thumbnail 😂😂😂

**@alwaisy** · 0 upvotes

> does it matter. i know it or don't know it. at least my coding agent does not care. in 2021. i did care so much what the fuck closures vs hoisting are. who cares now.

**@jobayerhossen** · 0 upvotes

> good

## Similar posts on daily.dev

- [NestJS Dependency Injection: Source Code, Type Erasure Hacks, and Building Your Own IoC Container from Scratch](https://daily.dev/posts/nestjs-dependency-injection-source-code-type-erasure-hacks-and-building-your-own-ioc-container-fr-74fnlhzd6) · Medium · 0 upvotes · 0 comments

---

Tags: [#typescript](https://daily.dev/tags/typescript), [#dependency-injection](https://daily.dev/tags/dependency-injection), [#nestjs](https://daily.dev/tags/nestjs)

[View this post on daily.dev](https://daily.dev/posts/how-dependency-injection-works-in-nestjs-htekyk7qh)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How Dependency Injection Works in NestJS","url":"https://daily.dev/posts/how-dependency-injection-works-in-nestjs-htekyk7qh","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-dependency-injection-works-in-nestjs-htekyk7qh"},"datePublished":"2026-07-10T08:36:47.675Z","dateModified":"2026-09-13T18:26:02.196Z","description":"A brief explainer on how dependency injection works in NestJS, using a pizza chef analogy to illustrate tight coupling vs. injected dependencies. Shows why...","image":"https://i.ytimg.com/vi/4BzJ13ZSDPY/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/4BzJ13ZSDPY/sddefault.jpg","isAccessibleForFree":true,"articleSection":"JavaScript Mastery","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"JavaScript Mastery","logo":"https://media.daily.dev/image/upload/s--i6Ls5Q5_--/f_auto/v1724338715/logos/javascriptmastery","url":"https://daily.dev/sources/javascriptmastery"},"commentCount":4,"discussionUrl":"https://daily.dev/posts/how-dependency-injection-works-in-nestjs-htekyk7qh","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":16},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":4}],"keywords":"typescript,dependency-injection,nestjs","timeRequired":"PT1M","video":{"@type":"VideoObject","name":"How Dependency Injection Works in NestJS","description":"A brief explainer on how dependency injection works in NestJS, using a pizza chef analogy to illustrate tight coupling vs. injected dependencies. Shows why...","thumbnailUrl":"https://i.ytimg.com/vi/4BzJ13ZSDPY/sddefault.jpg","uploadDate":"2026-07-10T08:36:47.675Z","duration":"PT1M","url":"https://api.daily.dev/r/hTEKYK7Qh","embedUrl":"https://www.youtube.com/embed/4BzJ13ZSDPY"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"JavaScript Mastery","item":"https://daily.dev/sources/javascriptmastery"},{"@type":"ListItem","position":3,"name":"How Dependency Injection Works in NestJS"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/how-dependency-injection-works-in-nestjs-htekyk7qh","comment":[{"@type":"Comment","text":"LOL! The thumbnail 😂😂😂","datePublished":"2026-07-11T04:49:01.748Z","url":"https://daily.dev/posts/hTEKYK7Qh#c-UChI3wVQA","author":{"@type":"Person","name":"Projekcomm","url":"https://daily.dev/projekcomm","image":"https://lh3.googleusercontent.com/a/ACg8ocLMal8dqtQpCaFKR_2Qj0-5jQ7_YZNHGq5ZMFQHZI4f0VWGwg7O=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"does it matter. i know it or don’t know it. at least my coding agent does not care. in 2021. i did care so much what the fuck closures vs hoisting are. who cares now.","datePublished":"2026-07-12T08:35:29.960Z","url":"https://daily.dev/posts/hTEKYK7Qh#c-sDTctkViB","author":{"@type":"Person","name":"Awais Alwaisy","url":"https://daily.dev/alwaisy","image":"https://avatars.githubusercontent.com/u/102944304?v=4"}},{"@type":"Comment","text":"good","datePublished":"2026-07-11T12:38:54.050Z","url":"https://daily.dev/posts/hTEKYK7Qh#c-IHmYsTDg1","author":{"@type":"Person","name":"Jobayer Hossen","url":"https://daily.dev/jobayerhossen","image":"https://lh3.googleusercontent.com/a/ACg8ocKPWsJsesL2GMS7y3dBEvZRr7NoVelPXt3Q6EGSbMyYadlvC_s=s96-c"}}]}
```

