Skip to content

Check at startup that the container can resolve every class handler and workflow #356

Open

Description

@adenhertog

Follow-up from #355 (#354).

Problem

Since #355, the bus only resolves class workflows from the container to handle a message, as it already does for class handlers. A container that can't resolve a class handler or workflow is now only found when a message arrives. That message then fails with ClassHandlerNotResolved or WorkflowHandlerFailed, is retried, and ends up in the dead letter queue. initialize() doesn't report it. bus-nestjs catches this at startup with its own introspect check (BusClassNotProvided), but other containers have no such check.

Also, without a container, build() throws ContainerNotRegistered for a class handler whose constructor takes arguments (bus-configuration.ts, the !this.container check in build()). Class workflows aren't checked, so a workflow that needs dependencies is constructed with undefined arguments for each message.

Proposal

  1. Add an optional ContainerAdapter.isRegistered?(type): boolean | Promise<boolean>. initialize() calls it, when the adapter has it, for every class handler and class workflow, and throws a named error listing the classes the container can't resolve, with the fix. Each common container has a matching call:
    • inversify: isBound
    • tsyringe: isRegistered
    • awilix: hasRegistration
    • Nest: introspect or has. bus-nestjs's nestContainer would implement it, and its own startup check could then reuse it.
  2. Extend build()'s ContainerNotRegistered check to class workflows whose constructor has length > 0. Make the error's wording (currently about "class handlers", with a classHandlerName field) cover both handlers and workflows.

The second is breaking for a bus without a container that registers a workflow whose constructor takes arguments, so it ships as minor with a MIGRATING.md entry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    roadmapPart of the project roadmap

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions