On this page
Late binding with SpellContract๏
Intermediate. Wire whole subsystems together without either side importing the other.
Excerpt. Define the ConfigContract Protocol, register its provider in
platform_book, and bind the consumer in services_book first. config_id and
service_id below are the IDs returned by those registrations. Run the complete
late-binding lesson
for the definitions and full sequence.
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
Expected outcome: service.config is the contracted provider object. The saved
lesson's equivalent store example prints region-ok; these excerpts do not print.
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๏
Late binding with SpellContract: runnable example โ Intermediate 36
Conduit categories as factories โ Intermediate 26
All intermediate examples ยท Level contents ยท Full contents