📘
@node-test/bus
  • @node-ts/bus
  • Getting started
    • Installation
    • Handling messages
    • Shutting down cleanly
  • Reference
    • Bus
    • BusConfiguration
    • BusInstance
  • Getting help
  • Guide
    • Messages
      • Events
      • Commands
      • System messages
    • Message attributes
      • Correlation id
      • Attributes
      • Sticky attributes
    • Workflows
      • Creating a workflow
      • Starting
      • Handling
      • State
      • Completing
      • Example
    • Transports
      • RabbitMQ
      • Amazon SQS
      • Redis
      • Custom transports
    • Persistence
      • Postgres
      • MongoDB
      • Creating a persistence
    • Serializers
      • Class serializer
    • Loggers
      • Custom loggers
    • Middleware
    • Lifecycle hooks
    • Retry Strategies
    • Dependency injection
    • Long running processes
Powered by GitBook
On this page

Was this helpful?

  1. Guide

Dependency injection

PreviousRetry StrategiesNextLong running processes

Last updated 3 years ago

Was this helpful?

If your service uses a dependency injection provider and you want to use it to resolve class based handlers and workflows, you can provide an adapter to @node-ts/bus-core for it to use.

This is provided as an adapter passed using .withContainer() to the configuration.

This example uses , but any IoC container that supports resolving instances via a class type will work.

import { Bus, ClassConstructor } from '@node-ts/bus-core'
import { Container } from 'inversify'

const start = async () => {
  const container = new Container()

  const bus = await Bus.configure()
    .withContainer({
      get <T>(type: ClassConstructor<T>) {
        return container.get<T>(type)
      }
    })
    .initialize()
}
inversify