Skip to main content

Module ctx

Module ctx 

Source
Expand description

Ctx typed service registry, Plugin, activation, Disposer (DESIGN §6.1, ADR-004).

Mapping from Cordis (ADR-004):

  • Stable service keys: a service is registered by trait-object type (ctx.provide::<dyn ModelProvider>(impl) / ctx.resolve::<dyn ModelProvider>); one implementation per key — a second registration is a named error.
  • Reversible registration: trait Plugin { fn apply(self, ctx: &mut Ctx) -> Result<Disposer, PluginError> } — everything apply installs (services, event handlers) is unwound by the returned Disposer.
  • inject → topology: plugins declare dependencies by name; PluginSet::activate runs them in a deterministic topological order (ties broken by declaration order); cycles are a named error.
  • Disposers unwind in reverse order exactly once, on explicit dispose() or on drop.

Static (compile-time) plugins only — crate::kian_plugins! assembles a PluginSet; dynamic loading (dylib/wasm) is deferred.

Structs§

Ctx
Typed service registry (Cordis ctx container). Service keys are stable: the key is the TypeId of the trait-object type (dyn Greeter) or of a concrete type; values are Arc<dyn Any + Send + Sync> wrappers around Arc<S>.
Disposer
Reversible side effect (Cordis disposer). Callbacks run in reverse insertion order, exactly once — on explicit Disposer::dispose or on drop. Registration and disposal are paired.
PluginSet
The compile-time plugin set assembled by crate::kian_plugins!. Activation order is derived from declared dependencies, not listing order.

Enums§

PluginError
Named errors for the plugin subsystem (acceptance criteria).

Traits§

Plugin
A statically-registered capability unit (ADR-004). apply installs services and event handlers into Ctx and returns the Disposer that unwinds them; dependencies are declared by plugin name and resolved by topological activation (the static equivalent of Cordis inject).
Service
Marker bound for services stored in Ctx: any 'static Send + Sync type (trait object or concrete) can occupy a service key.