On this page

Constructor dependency injection๏ƒ

Beginner โ†’ Intermediate. Annotations, explicit targets, collections.

Annotate a constructor parameter. Melder builds the graph.

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๏ƒ

All beginner examples ยท Level contents ยท Full contents

Canonical page source