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", permissions="create")
class MetricsHub:
pass
@md.scan_bind(existence="many", permissions="create")
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.
scan_bind takes everything bind() takes for a target โ spellframe,
binding_name, resolvable, disposal_method_names and your own metadata
keywords โ and permissions is required. Only the decorated class or function
itself is registered: its subclasses and instances are not, unless they are
decorated too.
Runnable examples๏
Scan bind decorator โ Intermediate 01
All intermediate examples ยท Level contents ยท Full contents