On this page

Late binding with SpellContract๏ƒ

Intermediate. Wire whole subsystems together without either side importing the other.

A SpellContract is a hole you leave on purpose. The class declares the shape it needs; the provider arrives later, across a link:

class ReportService:
    def __init__(
        self,
        config: ConfigContract = md.SpellContract(
            spellframe=ConfigContract, binding_name="platform",
        ),
    ) -> None:
        self.config = config        # โ† filled from another conduit entirely

Name your conduits after the resolution ideas your app already has โ€” platform, services, workflows โ€” and the conduit names become your factory layer. No abstract factories, no service locator, no imports between subsystems.

The order of operations is the law. Per dependency edge, in this exact order:

platform = platform_book.conjure(dynamic=True, name="platform")  # 1. provider
services = services_book.conjure(dynamic=True, name="services")  # 2. consumer
platform.link(services)                                          # 3. link โ€” AFTER both exist
services.add_spell_to_contract(                                  # 4. consumer pulls
    spell_id=config_id, conduit=platform, permissions="create",
)
service = services.meld(spell_id=service_id)                    # 5. meld completes the binding

Assemble the chain edge by edge, in dependency order. services can then feed workflows with the identical five steps one level up โ€” the finished product of one category becomes the dependency of the next.

Runnable examples๏ƒ

All intermediate examples ยท Level contents ยท Full contents

Canonical page source