Page Contents

Home > @loopback/context > Binding > toProvider

Binding.toProvider() method

Bind the key to a value computed by a Provider.

*

Signature:

toProvider(providerClass: Constructor<Provider<T>>): this;

Parameters

Parameter Type Description
providerClass Constructor<Provider<T>>  

Returns:

this

Example

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