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

sp core library.servicekey

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

Home > @microsoft/sp-core-library > ServiceKey

ServiceKey class

The ServiceKey is a lookup key that is used when calling ServiceScope.consume() to fetch a dependency.

Signature:

export default class ServiceKey<T>

Remarks

Every service key also provides a default implementation of the dependency, which will be automatically created in the root scope if the dependency is not found. Providing a default implementation ensures that new dependencies can be safely introduced without inadvertently breaking components that are loaded by an older host that does not provide the new dependency.

Properties

Property Modifiers Type Description
defaultCreator ServiceCreator<T> A callback function that constructs the default instance of this service.
id string A unique identifier for this service key.
name string The name of the service.

Methods

Method Modifiers Description
create(name, serviceClass) static Constructs a new ServiceKey whose default implementation will be a new instance of a TypeScript class that accepts the standard constructor parameter.
createCustom(name, defaultCreator) static Constructs a new ServiceKey whose default implementation will be obtained by invoking the specified callback.
Clone this wiki locally