On this page

Declarative binding by module๏ƒ

Intermediate. Register where the class lives.

Prefer to declare registration where the class lives? Tag it with @md.scan_bind, then register the whole module in one call.

services.py โ€” declare intent next to the code:

import melder as md


@md.scan_bind(existence="unique")
class MetricsHub:
    pass


@md.scan_bind(existence="many")
class JobTicket:
    pass

main.py โ€” decide when it actually binds:

import melder as md
import services

book = md.Spellbook()
bound = book.scan(services)        # โ† binds every tagged class in the module
conduit = book.conjure()

hub = conduit.meld("MetricsHub")

The decorator stores intent only โ€” nothing touches the runtime until scan() runs. Importing services registers nothing: no hidden global container filling up behind your back, no import-order puzzle to debug. You still decide when binding happens, and where.

Mix freely: scan a module, then bind() a few more by hand.


Runnable examples๏ƒ

All intermediate examples ยท Level contents ยท Full contents

Canonical page source