diff --git a/packages/dispatcher/src/dispatcher.ts b/packages/dispatcher/src/dispatcher.ts index 8ae5bf77..b896b508 100644 --- a/packages/dispatcher/src/dispatcher.ts +++ b/packages/dispatcher/src/dispatcher.ts @@ -204,12 +204,28 @@ export class Dispatcher { * * **Note**: This is only available for the root dispatcher. */ - inject(name: Name, value: DispatcherDependencies[Name]): void { + inject(name: Name, value: DispatcherDependencies[Name]): void + /** + * Inject dependencies to be available in this dispatcher and all its children. + * + * **Note**: This is only available for the root dispatcher. + */ + inject(deps: Partial): void + inject( + name: Name | Partial, + value?: DispatcherDependencies[Name], + ): void { if (this._parent) { throw new MtArgumentError('Cannot inject dependencies to child dispatchers') } - this._deps[name] = value + if (typeof name === 'object') { + for (const [k, v] of Object.entries(name)) { + (this._deps as any)[k] = v + } + } else { + this._deps[name] = value! + } } /**