Closed abdelrahman-salah closed 3 years ago
Hello @wessberg Thanks for the awesome package π
I'm probably missing something trivial but I can't get it to work π
sample ts file
import { DIContainer } from "@wessberg/di"; import { LoggerServiceContract } from "../domain/contracts/services/logger.service-contract"; import { LoggerService } from "../services/logger.service"; export function registerServices(injector: DIContainer): void { injector.registerSingleton<LoggerServiceContract, LoggerService>(); }
package usage
import { di } from "@wessberg/di-compiler"; import { createProgram, getDefaultCompilerOptions, createCompilerHost, ImportsNotUsedAsValues, } from "typescript"; const compilerOptions = getDefaultCompilerOptions(); compilerOptions.outDir = 'lib'; compilerOptions.importsNotUsedAsValues = ImportsNotUsedAsValues.Preserve; const compilerHost = createCompilerHost(compilerOptions); const program = createProgram( ["./src/index.ts"], compilerOptions, compilerHost ); program.emit(undefined, undefined, undefined, undefined, di({ program }));
result
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerServices = void 0; require("@wessberg/di"); require("../domain/contracts/services/logger.service-contract"); require("../services/logger.service"); function registerServices(injector) { /* HERE */ injector.registerSingleton(undefined, { identifier: "LoggerServiceContract", implementation: LoggerService }); } exports.registerServices = registerServices;
when I run the app I get the following error during this call injector.registerSingleton
injector.registerSingleton
ReferenceError: LoggerService is not defined
Do you have any hints on what am I doing wrong? Thanks
I forgot to add this to the compiler option compilerOptions.module = ModuleKind.CommonJS;
compilerOptions.module = ModuleKind.CommonJS;
Hello @wessberg Thanks for the awesome package π
I'm probably missing something trivial but I can't get it to work π
sample ts file
package usage
result
when I run the app I get the following error during this call
injector.registerSingleton
Do you have any hints on what am I doing wrong? Thanks