@elsikora/cladi
Version:
Zero-dependency TypeScript DI toolkit with typed tokens and scoped lifecycles.
57 lines (54 loc) • 2.22 kB
JavaScript
import { DIContainer } from '../class/di/container.class.js';
import { ConsoleLoggerService } from '../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 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 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 ConsoleLoggerService(options);
this.LOGGER?.debug("Logger instance created", { source: "InfrastructureFactory" });
return logger;
}
}
export { CoreFactory };
//# sourceMappingURL=core.factory.js.map