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

sp core library.servicescope.createandprovide

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

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

ServiceScope.createAndProvide() method

This is a shorthand function that is equivalent to constructing a new instance of the simpleServiceClass, then registering it by calling ServiceScope.provide().

Signature:

createAndProvide<T>(serviceKey: ServiceKey<T>, simpleServiceClass: {
        new (serviceScope: ServiceScope): T;
    }): T;

Parameters

Parameter Type Description
serviceKey ServiceKey<T> the key that can be used later to consume the service
simpleServiceClass { new (serviceScope: ServiceScope): T; } the TypeScript class to be constructed

Returns:

T

a newly constructed instance of simpleServiceClass

Clone this wiki locally