registerService Function

Module
import { registerService } from "@tsed/common"
Source/packages/common/src/di/registries/ProviderRegistry.ts

Overview

const registerService: (provider: any, instance?: any) =>; void;

Description

Add a new service in the ProviderRegistry. This service will be built when InjectorService will be loaded.

Example

import {registerService, InjectorService} from "@tsed/common";

export default class MyFooService {
    constructor(){}
    getFoo() {
        return "test";
    }
}

registerService({provide: MyFooService});
// or
registerService(MyFooService);

const injector = new InjectorService();
injector.load();

const myFooService = injector.get<MyFooService>(MyFooService);
myFooService.getFoo(); // test