--- myst: html_meta: description: "Learn constructor dependency injection in Melder and follow a complete runnable Python example with typed dependencies." --- # Constructor dependency injection **Beginner → Intermediate.** Annotations, explicit targets, collections. Annotate a constructor parameter. Melder builds the graph. What an annotation selects depends on what it is. A **class** selects the spells of that type — a class bound bare, or an existing object of that class — and nothing else: a category that happens to share the class's name does not turn its members into providers. A **Protocol** selects the spells bound under it as their contract. A **`TYPE_CHECKING`-only import**, which leaves a string at runtime, resolves by name to a type or a contract, never to a string category. `list[...]` gathers the group the annotation's kind names: every spell of the class, every implementer of the Protocol, or — for a string — every member of the category or type of that name. ```python class ReportService: def __init__(self, database: Database) -> None: # ← injected self.database = database book.bind(spell=Database, existence="unique") book.bind(spell=ReportService, existence="unique") conduit = book.conjure() report = conduit.meld("ReportService") ``` ## Runnable examples - [Constructor di by annotation](../examples/intermediate/15-constructor-di-by-annotation.md) — Intermediate 15 - [Typed melding](../examples/beginner/16-typed-melding.md) — Beginner 16 [All beginner examples](../examples/beginner/index.md) · [Level contents](index.md) · [Full contents](../contents.md) [Canonical page source](https://github.com/Synaptic724/melder/blob/0b443cc5f6f77b37ae2f60ff298bec0ea9497d7a/README.md)