On this page

What you can bind๏ƒ

Registration is ordinary Python code. The saved lessons demonstrate three useful inputs: a class Melder can construct, a function that supplies a value, and an instance you already constructed.

Pick the form that expresses your ownership๏ƒ

Use the class examples when you want to study construction and instance lifetimes. Use the function and prebuilt-instance examples when a value comes from application setup you already control. Read their assertions before assuming that all registration forms have interchangeable lifetime behavior.

Register a group of services๏ƒ

The collection examples show both a normal loop over registrations and a prebuilt registry bound as one value. These answer different questions: registering several services exposes several graph entries; supplying a registry exposes the collection your application already owns.

The linked lessons contain the full classes, setup, and checks. Work through one form at a time, then use the capstone to put them together.

The workflow in code๏ƒ

These are the core steps from the saved example. Use its complete linked script for all class definitions and setup.

 1def main() -> None:
 2    book = md.Spellbook()
 3    book.bind(spell=make_settings, existence="unique")
 4
 5    prebuilt = AlreadyBuilt("built-by-hand")
 6    book.bind(spell=prebuilt, existence="unique")
 7
 8    conduit = book.conjure()
 9
10    settings = conduit.meld(spell=make_settings)
11    print("function spell melded ->", settings)
12    again = conduit.meld(spell=make_settings)
13    print("unique law: same product back?", settings is again)
14
15    held = conduit.meld(spell=prebuilt)
16    assert held is prebuilt and held.label == "built-by-hand"
17    print("instance spell melded:", held.label)

Runnable examples๏ƒ

All beginner examples ยท Level contents ยท Full contents

Canonical page source