Skip to content
This repository has been archived by the owner on Oct 23, 2021. It is now read-only.

sp core library.servicescope.consume

John Nguyen edited this page Apr 22, 2021 · 2 revisions

Home > @microsoft/sp-core-library > ServiceScope > consume

ServiceScope.consume() method

Consumes a service from the service scope.

Signature:

consume<T>(serviceKey: ServiceKey<T>): T;

Parameters

Parameter Type Description
serviceKey ServiceKey<T> the key that was used when provide() was called to register the service

Returns:

T

the service instance

Remarks

Components should call this function to "consume" a dependency, i.e. look up the serviceKey and return the registered service instance. If the instance cannot be found, then a default instance will be automatically created and registered with the root ServiceScope.

Clone this wiki locally