/** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2020-11-06 14:20:32 * @modify date 2021-08-11 19:59:47 * @desc [description] */ import { getSingleton } from "../helpers/singletonMethod"; import { INopePackageLoaderConstructor } from "../types/nope"; import { INopeDispatcherOptions } from "../types/nope/nopeDispatcher.interface"; import { generateNopeBasicPackage } from "./generateNopeBasicPackage"; import { NopePackageLoader } from "./nopePackageLoader"; /** * Function to extract a Singleton Dispatcher * @param options The provided options for the Dispatcher */ export function getPackageLoader( options: INopeDispatcherOptions, singleton = true, constructorClass: INopePackageLoaderConstructor = null ) { if (constructorClass === null || constructorClass === undefined) { constructorClass = NopePackageLoader; } const create = () => { // Create a loader const loader = new constructorClass(); // load the default Package: loader .addPackage(generateNopeBasicPackage(options, singleton)) .catch((e) => { throw e; }); return loader; }; if (singleton) { // Create a singaleton if required. // use the container to receive the // singleton object const container = getSingleton("nopeBackendPackageLoader.instance", create); return container.instance; } // No singleton is required => // create a new instance. return create(); }