Registry for managing contexts and their dependencies.

Maintains the dependency graph and provides contexts in initialization order.

const registry = new ContextRegistry();

registry.register(productsContext);
registry.register(ordersContext);
registry.register(inventoryContext);

const contexts = registry.getContextsInOrder();
// Contexts in dependency order

Accessors

Constructors

Methods

  • Registers a context.

    Parameters

    • context: Context

      The context to register

    Returns void

    If a context with the same name is already registered

    registry.register(new ProductsContext());
    
  • Gets a context by name.

    Parameters

    • name: string

      The context name

    Returns undefined | Context

    The context if found, undefined otherwise

    const context = registry.get('products-context');
    
  • Gets contexts in topological order (dependency order).

    Contexts are returned in the order they should be initialized. Plugins are initialized before contexts that depend on them.

    Returns Context[]

    Array of contexts in dependency order

    If circular dependencies exist

    If a dependency is not found

    const contexts = registry.getContextsInOrder();
    for (const context of contexts) {
    await context.initialize(config);
    }
  • Gets contexts in reverse topological order.

    Useful for shutdown (shutdown in reverse initialization order).

    Returns Context[]

    Array of contexts in reverse dependency order