Page Contents

Home > @loopback/service-proxy > ServiceMixinDoc > serviceProvider

ServiceMixinDoc.serviceProvider() method

Add a service to this application.

Signature:

serviceProvider<S>(provider: Class<Provider<S>>): Binding<S>;

Parameters

Parameter Type Description
provider Class<Provider<S>> The service provider to register.

Returns:

Binding<S>

Example

export interface GeocoderService {
  geocode(address: string): Promise<GeoPoint[]>;
}

export class GeocoderServiceProvider implements Provider<GeocoderService> {
  constructor(
    @inject('datasources.geocoder')
    protected dataSource: juggler.DataSource = new GeocoderDataSource(),
  ) {}

  value(): Promise<GeocoderService> {
    return getService(this.dataSource);
  }
}

app.serviceProvider(GeocoderServiceProvider);