TxQueueContainer

Wrapper classes around inversifyJS container library. You can create a component by inject all its dependencies.

usages

  • Create a component Q1Component using TxQueueContainer injector.

// define a component something like this.
  @injectable()
  export class Q1Component {
    @inject(TxTYPES.TxQueuePoint) queuepoint;
 
    constructor() {
    }
 
    async init() {
      ...
    }
  }
 
  // prepare injector for Q1Component - this done one time.
  TxQueueContainer.setDriver(TxConnectorRabbitMQ); // optional, otherwise use default TxConnectorRabbitMQ
  TxQueueContainer.addComponent<Q1Component>(Q1Component, 'Q1Component');
     
  // create new 'Q1Component' component under the name 'Q1COMPONENT::QUEUE::CONTAINER'
  co = TxQueueContainer.get('Q1Component', 'Q1COMPONENT::QUEUE::CONTAINER');
 
  // send something to queue.
  co.queuepoint.queue.next(..);
  • Create a component Q2 which has some other member in it.

// define Q2Component which has other member.
  @injectable()
  export class QMember {
    @inject('QMember::name') name: string;
 
    constructor() {}
    ....
  }
 
  @injectable()
  export class Q3Component {
    @inject(TxTYPES.TxQueuePoint) queuepoint;
    @inject('QMember') qmember: QMember;
 
    constructor() {}
 
    async init() { ... }
 
    getQMember() { return this.qmember; }
  }
 
   // prepare injector for Q2Component, this done once
  TxQueueContainer.setDriver(TxConnectorRabbitMQ);
  TxQueueContainer.addComponent<R1Component>(Q3Component, 'Q3Component');
  TxQueueContainer.addBind<QMember>(QMember, 'QMember');
 
  // create 'Q3Component' where name 'tsemach' is inject into QMember of Q2Component
  TxQueueContainer.addBindConstantValue<string>('QMember::name', 'tsemach');        
  cp = TxQueueContainer.get('Q3Component', 'Q3COMPONENT::QUEUE::CONTAINER');

Last updated