UNPKG

@elsikora/cladi

Version:

Zero-dependency TypeScript DI toolkit with typed tokens and scoped lifecycles.

59 lines (55 loc) 2.31 kB
'use strict'; var container_class = require('../class/di/container.class.js'); var consoleLogger_service = require('../service/console-logger.service.js'); /** * Factory for creating DI infrastructure components. */ class CoreFactory { LOGGER; /** * Creates a new infrastructure factory. * @param {ICoreFactoryOptions} options - The options to use for the factory. * @see {@link https://elsikora.com/docs/cladi/core-concepts/factory} */ constructor(options) { this.LOGGER = options.logger ?? new consoleLogger_service.ConsoleLoggerService(); } /** * Creates a new factory instance. * Useful for static composition-root bootstrap flows. * @param {ICoreFactoryOptions} options - The options to use for the factory. * @returns {CoreFactory} A new factory instance. * @see {@link https://elsikora.com/docs/cladi/core-concepts/factory} */ static getInstance(options) { return new CoreFactory(options); } /** * Creates a new advanced DI container instance. * @param {IDIContainerOptions} options - The options to use for the DI container. * @returns {IDIContainer} A new advanced DI container. */ createDIContainer(options = {}) { this.LOGGER?.debug("Creating new DI container instance", { source: "InfrastructureFactory" }); const container = new container_class.DIContainer(options); this.LOGGER?.debug("DI container instance created", { source: "InfrastructureFactory" }); return container; } /** * Creates a new logger instance. * @param {IConsoleLoggerOptions} options - The options to use for the logger. * @returns {ILogger} A new logger instance. * @see {@link https://elsikora.com/docs/cladi/services/logging} */ createLogger(options) { this.LOGGER?.debug("Creating new logger instance", { context: { level: options.level, loggerSource: options.source }, source: "InfrastructureFactory", }); const logger = new consoleLogger_service.ConsoleLoggerService(options); this.LOGGER?.debug("Logger instance created", { source: "InfrastructureFactory" }); return logger; } } exports.CoreFactory = CoreFactory; //# sourceMappingURL=core.factory.js.map