Allows to manage singleton instances of any class-oriented development.

import { Factory, type FactoryInstance } from '@amjs/js-utils';

class MyClass {
config: any;

constructor(config: any) {
this.config = config;
}
}

const fi: FactoryInstance = Factory.i();
fi.register('my-class', MyClass);
console.log(fi.has('my-class')); // true
console.log(fi.list()); // ['my-class']

const mCi = fi.create('my-class', 'some-value');
console.log(mCi.config); // 'some-value'

Implements

Constructors

Methods

Constructors

Methods

  • Creates a singleton of a registered class constructor

    Type Parameters

    • T

    Parameters

    • name: string

      Identifier of the class constructor within the registry

    • Optionalvalue: any

      To pass as argument for the class constructor

    Returns any

    Singleton of the class, or undefined in other case

  • Returns whether class constructor is being registered at the factory singleton.

    Parameters

    • name: string

      Class constructor identifier within factory registry

    Returns boolean

    true if exists, false in other case

  • Registers a class constructor identified by the {name} parameter

    Parameters

    • name: string

      Class constructor unique identifier

    • Constructor: <T>(value?: any) => T

      To be registered

    Returns void