# DynamicHub: The Routing Layer

> How activations are registered and how method calls are routed.

## Overview

`DynamicHub` is itself an `Activation` that routes calls to registered child activations. It's defined in `plexus-core/src/plexus/plexus.rs`.

```rust
let hub = DynamicHub::new("myservice")
    .register(Echo::new())        // Leaf activation
    .register(Health::new())      // Another leaf
    .register_hub(Solar::new());  // Hub activation (has its own children)
```

## Registration

- `.register()` — for leaf activations (no children)
- `.register_hub()` — for activations that themselves contain children (enables nested routing like `myservice.solar.mercury.info`)
- The hub namespace becomes the root path segment

## Introspection Methods

DynamicHub automatically provides:
- `{namespace}.call` — route calls to registered activations
- `{namespace}.hash` — configuration hash for cache invalidation
- `{namespace}.list_activations` — enumerate registered activations
- `{namespace}.schema` — full schema tree

## Real-World Builder Example

From `plexus-substrate/src/builder.rs`:

```rust
pub async fn build_plexus_rpc() -> Arc<DynamicHub> {
    let arbor = Arbor::with_context_type(ArborConfig::default())
        .await.expect("Failed to initialize Arbor");

    let cone = Cone::with_context_type(ConeStorageConfig::default(), arbor.storage())
        .await.expect("Failed to initialize Cone");

    // Use Arc::new_cyclic for activations that need parent references
    let hub = Arc::new_cyclic(|weak_hub: &Weak<DynamicHub>| {
        // Inject parent context into activations that need it
        arbor.inject_parent(weak_hub.clone());
        cone.inject_parent(weak_hub.clone());

        DynamicHub::new("substrate")
            .register(Health::new())
            .register(Echo::new())
            .register(Bash::new())
            .register(arbor)
            .register(cone)
            .register_hub(Solar::new())
    });

    hub
}
```

## Hub Activations (Nested Routing)

For activations with their own child tree, implement `ChildRouter` and register with `.register_hub()`:

```rust
DynamicHub::new("substrate")
    .register_hub(Solar::new())  // Solar has children like mercury, venus, etc.
```

This enables paths like `substrate.solar.mercury.info`.

## Source Paths

| Component | Path |
|-----------|------|
| DynamicHub implementation | `plexus-core/src/plexus/plexus.rs` |
| Substrate builder | `plexus-substrate/src/builder.rs` |
