Page Contents

Home > @loopback/context > Provider

Provider interface

Providers allow developers to compute injected values dynamically, with any dependencies required by the value getter injected automatically from the Context.

Signature:

export interface Provider<T> 

Example

export class DateProvider implements Provider<Date> {
  constructor(@inject('stringDate') private param: String){}
  value(): Date {
    return new Date(param);
  }
}

ctx.bind('stringDate').to('2017-01-01')
ctx.bind('provider_key').toProvider(DateProvider);

const value = ctx.getAsync('provider_key');
// value is a Date instance

Methods

Method Description
value()