{"id":13847270,"url":"https://github.com/wessberg/DI-compiler","last_synced_at":"2025-07-12T08:31:30.065Z","repository":{"id":22576109,"uuid":"92279007","full_name":"wessberg/DI-compiler","owner":"wessberg","description":"A Custom Transformer for Typescript that enables compile-time Dependency Injection","archived":false,"fork":false,"pushed_at":"2024-10-31T00:10:20.000Z","size":1322,"stargazers_count":83,"open_issues_count":9,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-02T09:42:46.916Z","etag":null,"topics":["custom-transformer","dependency-injection","di","inversion","ioc","reflection","service-container","singleton","transient","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wessberg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"wessberg","patreon":"wessberg"}},"created_at":"2017-05-24T10:13:25.000Z","updated_at":"2025-02-27T20:50:00.000Z","dependencies_parsed_at":"2024-06-18T19:48:02.334Z","dependency_job_id":"88ae2413-8386-4ac5-9374-b7696f763738","html_url":"https://github.com/wessberg/DI-compiler","commit_stats":{"total_commits":289,"total_committers":6,"mean_commits":"48.166666666666664","dds":0.02768166089965396,"last_synced_commit":"9619c1d44bde0b4eda8c6b85f84ad180fe065203"},"previous_names":[],"tags_count":98,"template":false,"template_full_name":null,"purl":"pkg:github/wessberg/DI-compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2FDI-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2FDI-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2FDI-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2FDI-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wessberg","download_url":"https://codeload.github.com/wessberg/DI-compiler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2FDI-compiler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264962219,"owners_count":23689764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom-transformer","dependency-injection","di","inversion","ioc","reflection","service-container","singleton","transient","typescript"],"created_at":"2024-08-04T18:01:15.184Z","updated_at":"2025-07-12T08:31:29.275Z","avatar_url":"https://github.com/wessberg.png","language":"TypeScript","readme":"\u003c!-- SHADOW_SECTION_LOGO_START --\u003e\n\n\u003cdiv\u003e\u003cimg alt=\"Logo\" src=\"https://raw.githubusercontent.com/wessberg/di-compiler/master/documentation/asset/di-logo.png\" height=\"150\"   /\u003e\u003c/div\u003e\n\n\u003c!-- SHADOW_SECTION_LOGO_END --\u003e\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_SHORT_START --\u003e\n\n\u003e A Custom Transformer for Typescript that enables compile-time Dependency Injection\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_SHORT_END --\u003e\n\n\u003c!-- SHADOW_SECTION_BADGES_START --\u003e\n\n\u003ca href=\"https://npmcharts.com/compare/%40wessberg%2Fdi-compiler?minimal=true\"\u003e\u003cimg alt=\"Downloads per month\" src=\"https://img.shields.io/npm/dm/%40wessberg%2Fdi-compiler.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/%40wessberg%2Fdi-compiler\"\u003e\u003cimg alt=\"NPM version\" src=\"https://badge.fury.io/js/%40wessberg%2Fdi-compiler.svg\"    /\u003e\u003c/a\u003e\n\u003cimg alt=\"Dependencies\" src=\"https://img.shields.io/librariesio/github/wessberg%2Fdi-compiler.svg\"    /\u003e\n\u003ca href=\"https://github.com/wessberg/di-compiler/graphs/contributors\"\u003e\u003cimg alt=\"Contributors\" src=\"https://img.shields.io/github/contributors/wessberg%2Fdi-compiler.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/prettier/prettier\"\u003e\u003cimg alt=\"code style: prettier\" src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg alt=\"License: MIT\" src=\"https://img.shields.io/badge/License-MIT-yellow.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.patreon.com/bePatron?u=11315442\"\u003e\u003cimg alt=\"Support on Patreon\" src=\"https://img.shields.io/badge/patreon-donate-green.svg\"    /\u003e\u003c/a\u003e\n\n\u003c!-- SHADOW_SECTION_BADGES_END --\u003e\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_LONG_START --\u003e\n\n## Description\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_LONG_END --\u003e\n\nThis library enables you to use [the DI library](https://github.com/wessberg/di) by providing several ways to transform your source code into a representation that it expects.\nYou can use it as a [Node.js loader](#usage-as-a-nodejs-loader), as [an API](#usage-as-an-api), and even as a [`Custom Transformer`](#usage-as-a-typescript-custom-transformer) for Typescript.\n\nIntegration with popular tools such as Webpack, esbuild, Rollup, or something else is easy, and this README provides several examples of ways it can be achieved.\n\nIt is optimized for _performance_, but how fast it can go depends on your setup. Please see the [Optimization](#optimization) section for details on how to tweak `DI-Compiler`\nso that it works most efficiently.\n\n\u003c!-- SHADOW_SECTION_FEATURES_START --\u003e\n\n### Features\n\n\u003c!-- SHADOW_SECTION_FEATURES_END --\u003e\n\n- Really lightweight\n- Really fast\n- Low-level implementation that can be used as the foundation for other tools such as Loaders, Plugins, and others.\n- It doesn't ask you to reflect metadata or to annotate your classes with decorators. \"It just works\".\n- Works without a TypeScript program, so you can use it with tools like babel, esbuild, and SWC for the best possible performance.\n\n\u003c!-- SHADOW_SECTION_FEATURE_IMAGE_START --\u003e\n\n\u003c!-- SHADOW_SECTION_FEATURE_IMAGE_END --\u003e\n\n\u003c!-- SHADOW_SECTION_BACKERS_START --\u003e\n\n## Backers\n\n### Patreon\n\n\u003ca href=\"https://www.patreon.com/bePatron?u=11315442\"\u003e\u003cimg alt=\"Patrons on Patreon\" src=\"https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dwessberg%26type%3Dpatrons\"  width=\"200\"  /\u003e\u003c/a\u003e\n\n\u003c!-- SHADOW_SECTION_BACKERS_END --\u003e\n\n\u003c!-- SHADOW_SECTION_TOC_START --\u003e\n\n## Table of Contents\n\n- [Description](#description)\n  - [Features](#features)\n- [Backers](#backers)\n  - [Patreon](#patreon)\n- [Table of Contents](#table-of-contents)\n- [Install](#install)\n  - [npm](#npm)\n  - [Yarn](#yarn)\n  - [pnpm](#pnpm)\n  - [Peer Dependencies](#peer-dependencies)\n- [Usage](#usage)\n  - [Usage as an API](#usage-as-an-api)\n  - [Usage as a Node.js loader](#usage-as-a-nodejs-loader)\n  - [Loader SourceMaps](#loader-sourcemaps)\n  - [Loader caching](#loader-caching)\n  - [Customizing DI-Compiler when used as a loader](#customizing-di-compiler-when-used-as-a-loader)\n  - [Usage as a TypeScript Custom Transformer](#usage-as-a-typescript-custom-transformer)\n  - [Usage with TypeScript's Compiler APIs](#usage-with-typescripts-compiler-apis)\n  - [Usage with ts-nodes programmatic API](#usage-with-ts-nodes-programmatic-api)\n  - [Usage with Rollup](#usage-with-rollup)\n    - [Usage with @rollup/plugin-typescript](#usage-with-rollupplugin-typescript)\n  - [Usage with Webpack](#usage-with-webpack)\n    - [Usage with awesome-typescript-loader](#usage-with-awesome-typescript-loader)\n    - [Usage with ts-loader](#usage-with-ts-loader)\n- [Options](#options)\n- [Optimization](#optimization)\n  - [Optimization 1: Activate `preserveValueImports` in your tsconfig CompilerOptions](#optimization-1-activate-preservevalueimports-in-your-tsconfig-compileroptions)\n  - [Optimization 2: Pass in one or more identifiers to consider instances of DIContainer instead of relying on partial evaluation](#optimization-2-pass-in-one-or-more-identifiers-to-consider-instances-of-dicontainer-instead-of-relying-on-partial-evaluation)\n- [Contributing](#contributing)\n- [FAQ](#faq)\n  - [DI-Compiler doesn't correctly update all my calls to the DIContainer methods](#di-compiler-doesnt-correctly-update-all-my-calls-to-the-dicontainer-methods)\n  - [How does it work, exactly?](#how-does-it-work-exactly)\n- [License](#license)\n\n\u003c!-- SHADOW_SECTION_TOC_END --\u003e\n\n\u003c!-- SHADOW_SECTION_INSTALL_START --\u003e\n\n## Install\n\n### npm\n\n```\n$ npm install @wessberg/di-compiler\n```\n\n### Yarn\n\n```\n$ yarn add @wessberg/di-compiler\n```\n\n### pnpm\n\n```\n$ pnpm add @wessberg/di-compiler\n```\n\n### Peer Dependencies\n\n`@wessberg/di-compiler` depends on `typescript`, so you need to manually install this as well.\n\nYou may also need to install `pirates` depending on the features you are going to use. Refer to the documentation for the specific cases where it may be relevant.\n\n\u003c!-- SHADOW_SECTION_INSTALL_END --\u003e\n\n\u003c!-- SHADOW_SECTION_USAGE_START --\u003e\n\n## Usage\n\n\u003c!-- SHADOW_SECTION_USAGE_END --\u003e\n\nThere are multiple ways you can use DI-compiler, depending on your setup:\n\n- [As an API](#usage-as-an-api)\n- [As a TypeScript Custom Transformer](#usage-as-a-typescript-custom-transformer)\n- [As a modern Node.js loader](#usage-as-a-nodejs-loader)\n\n### Usage as an API\n\nThe simplest possible way to use DI-Compiler is with its `transform` function:\n\n```ts\nimport {transform} from \"@wessberg/di-compiler\";\nconst {code} = transform(`\\\n\timport {DIContainer} from \"@wessberg/di\";\n\tconst container = new DIContainer();\n\tclass Foo {}\n\tcontainer.registerSingleton\u003cFoo\u003e();\n`);\n```\n\nIn this example, the compiler knows that `container` is an instance of [DIContainer](https://github.com/wessberg/di) based on the source text. However, you may be importing an instance of DIContainer\nfrom another file, in which case the compiler may not be able to statically infer that an identifier is an instance of DIContainer. For example:\n\n```ts\ntransform(`\\\n\timport {container} from \"./services\";\n\t// There may not be a way to statically determine whether or\n\t// not \\`container\\` is an instance of DIContainer at this point\n\tcontainer.get\u003cFoo\u003e();\n`);\n```\n\nTo help the compiler out, and to improve performance, you can pass in one or more identifiers in the source text that should be considered instances of DIContainer:\n\n```ts\ntransform(\n\t`\\\n\timport {container} from \"./services\";\n\tcontainer.get\u003cFoo\u003e();\n`,\n\t{\n\t\t// Treat identifiers named `container` as instances of DIContainer\n\t\tidentifier: \"container\"\n\t}\n);\n```\n\nIf you want a source map to be generated, make sure to pass that option in as a TypeScript [CompilerOption](https://www.typescriptlang.org/tsconfig#sourceMap):\n\n```ts\nconst {code, map} = transform(`...`, {\n\tcompilerOptions: {\n\t\tsourceMap: true\n\t}\n});\n```\n\nYou can pass in a cache to use as an option. This must be a data structure that conforms to that of a standard JavaScript [Map data structure](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map):\n\n```ts\nimport {transform, type TransformResult} from \"@wessberg/di-compiler\";\nconst cache = new Map\u003cstring, TransformResult\u003e();\n\ntransform(`...`, {\n\tcache\n});\n```\n\n### Usage as a Node.js loader\n\nA very convenient way to use `DI-Compiler` is as a loader directly with Node.js.\n\nIf your codebase is based on **native ESM**, and **if you use Node.js v.18.6.0 or newer**, pass it as a loader via the command line\n\n```\nnode --import @wessberg/di-compiler/loader\n```\n\nThis is not enough on its own to teach Node.js to understand TypeScript syntax, so you'll still need to couple it with a loader like [`ts-node`](https://github.com/TypeStrong/ts-node), [`tsx`](https://github.com/esbuild-kit/tsx) or [`esm-loader`](https://github.com/esbuild-kit/esm-loader).\n\nFor example, here's how to use it with the native ESM loader for [`ts-node`](https://github.com/TypeStrong/ts-node):\n\n```\nnode --import @wessberg/di-compiler/loader --import ts-node/esm\n```\n\nAnd, here's how to use it with [`tsx`](https://github.com/esbuild-kit/tsx):\n\n```\nnode --import @wessberg/di-compiler/loader --import tsx\n```\n\nFinally, here's how you can use it with [`esm-loader`](https://github.com/esbuild-kit/esm-loader):\n\n```\nnode --import @wessberg/di-compiler/loader --import @esbuild-kit/esm-loader\n```\n\nAlternatively, if you don't use ESM in your project, or if you're running an older version of Node.js, DI-Compiler can be used as a loader too.\nFor example, here's how to use it in combination with [`ts-node`](https://github.com/TypeStrong/ts-node) in a CommonJS project:\n\n```\nnode -r @wessberg/di-compiler/loader -r ts-node\n```\n\n\u003e In all of the above configurations, for both ESM and CommonJS loaders, there is no TypeScript _Program_ context, nor is there a Type checker, so `DI-Compiler` will attempt to determinate programmatically whether or not the identifiers across your files reference instances of `DIContainer` or not, by performing partial evaluation on compile time. Please see the [Optimization](#optimization) section for details on how this process can be optimized.\n\n### Loader SourceMaps\n\nBy default, SourceMaps will be generated and inlined inside the loaded modules if the `sourceMap` option is `true` inside the resolved tsconfig.\n\n### Loader caching\n\nBy default, DI-Compiler maintains a disk cache of transformation results from previously evaluated files. That means that successive loads of the same files will\nbe extremely fast.\n\n### Customizing DI-Compiler when used as a loader\n\nYou can pass in a few options to DI-Compiler via command line options:\n\n| Environment Variable        | Description                                                                                                                 |\n| --------------------------- | --------------------------------------------------------------------------------------------------------------------------- |\n| `DI_COMPILER_TSCONFIG_PATH` | The path to the `tsconfig.json` file to use                                                                                 |\n| `DI_COMPILER_IDENTIFIER`    | A comma-separated list of identifiers that should be considered instances of DIContainer when transforming the source files |\n| `DI_COMPILER_DISABLE_CACHE` | If set, no disk caching will be used.                                                                                       |\n\nAlternatively, you can add a `di` property to your `tsconfig` where you can customize its behavior without setting environment variables:\n\n```js\n// Inside your tsconfig.json\n{\n\t\"di\": {\n\t\t\"identifier\": \"container\",\n\t\t\"disableCache\": false\n\t},\n\t\"compilerOptions\": {\n\t\t// ...\n\t}\n}\n```\n\n### Usage as a TypeScript Custom Transformer\n\nYou can use the DI-Compiler anywhere TypeScript [`Custom Transformers`](https://github.com/Microsoft/TypeScript/pull/13940) can be used.\nOne advantage of this approach is that you often have access to a TypeScript _Program_, which can be leveraged by the DI-Compiler to fully understand\nthe structure of your program and specifically the type hierarchy and whether or not an identifier is an instance of [DIContainer](https://github.com/wessberg/di), for example.\n\nA few examples of ways to use DI-Compiler as a Custom Transformer include:\n\n- [With TypeScript's Compiler APIs](#usage-with-typescripts-compiler-apis)\n- [With ts-nodes programmatic API](#usage-with-ts-nodes-programmatic-api)\n- [With Rollup](#usage-with-rollup)\n\n### Usage with TypeScript's Compiler APIs\n\nThere's several ways to do this, but here's a simple example:\n\n```typescript\nimport {createProgram, getDefaultCompilerOptions, createCompilerHost} from \"typescript\";\nimport {di} from \"@wessberg/di-compiler\";\n\nconst compilerOptions = getDefaultCompilerOptions();\nconst compilerHost = createCompilerHost(compilerOptions);\n\n// Create a Typescript program\nconst program = createProgram([\"my-file-1.ts\", \"my-file-2.ts\"], compilerOptions, compilerHost);\n\n// Transform the SourceFiles within the program, and pass them through the 'di' transformer\nprogram.emit(undefined, undefined, undefined, undefined, di({program}));\n```\n\n### Usage with ts-nodes programmatic API\n\n[`ts-node`](https://github.com/TypeStrong/ts-node) can also be used programmatically. Here's an example of how you may combine it with DI-Compiler:\n\n```typescript\nimport {di} from \"@wessberg/di-compiler\";\n\nrequire(\"ts-node\").register({\n\ttransformers: program =\u003e di({program})\n});\n```\n\n### Usage with Rollup\n\nThere are a few TypeScript plugins for Rollup that support Custom Transformers, and DI-Compiler can be easily integrated with them.\n\n#### Usage with @rollup/plugin-typescript\n\nHere's how you may integrate DI-Compiler with [@rollup/plugin-typescript](https://www.npmjs.com/package/@rollup/plugin-typescript):\n\n```typescript\nimport ts from \"@rollup/plugin-typescript\";\nimport {di} from \"@wessberg/di-compiler\";\n\nexport default {\n\tinput: \"...\",\n\toutput: [\n\t\t/* ... */\n\t],\n\tplugins: [\n\t\tts({\n\t\t\ttransformers: program =\u003e di({program})\n\t\t})\n\t]\n};\n```\n\n### Usage with Webpack\n\nThere are two popular TypeScript loaders for Webpack that support Custom Transformers, and you can use DI-Compiler with both of them:\n\n- [With awesome-typescript-loader](#usage-with-awesome-typescript-loader)\n- [With ts-loader](#usage-with-ts-loader)\n\n#### Usage with awesome-typescript-loader\n\nHere's how it can be used with [awesome-typescript-loader](https://github.com/s-panferov/awesome-typescript-loader):\n\n```typescript\nimport {di} from \"@wessberg/di-compiler\";\nconst config = {\n\t// ...\n\tmodule: {\n\t\trules: [\n\t\t\t{\n\t\t\t\t// Match .mjs, .js, .jsx, and .tsx files\n\t\t\t\ttest: /(\\.mjs)|(\\.[jt]sx?)$/,\n\t\t\t\tloader: \"awesome-typescript-loader\",\n\t\t\t\toptions: {\n\t\t\t\t\t// ...\n\t\t\t\t\tgetCustomTransformers: program =\u003e di({program})\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t}\n\t// ...\n};\n```\n\n#### Usage with ts-loader\n\n[ts-loader](https://github.com/TypeStrong/ts-loader) can be used in exactly the same way as `awesome-typescript-loader`:\n\n```typescript\nimport {di} from \"@wessberg/di\";\nconst config = {\n\t// ...\n\tmodule: {\n\t\trules: [\n\t\t\t{\n\t\t\t\t// Match .mjs, .js, .jsx, and .tsx files\n\t\t\t\ttest: /(\\.mjs)|(\\.[jt]sx?)$/,\n\t\t\t\tloader: \"ts-loader\",\n\t\t\t\toptions: {\n\t\t\t\t\t// ...\n\t\t\t\t\tgetCustomTransformers: program =\u003e di({program})\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t}\n\t// ...\n};\n```\n\n## Options\n\nThe [`transform`](#usage-as-an-api) function, as well as the [`di` Custom Transformer](#usage-as-a-typescript-custom-transformer) takes\nthe same set of base options to configure tehir behavior. All of these options are optional:\n\n| Option            | Type                       | Description                                                                                                                                                                                       |\n| ----------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `program`         | TypeScript Program         | A full TypeScript program. When given, a Typechecker will be used to understand the type hierarchy of the application and to determine whether or not identifiers are instances of `DIContainer`. |\n| `typescript`      | TypeScript module          | If given, the TypeScript version to use internally for all operations.                                                                                                                            |\n| `identifier`      | `string[]` or `string`     | One or more identifiers in the source text that should be considered instances of DIContainer. Note: If a Program is passed, this option will be ignored.                                         |\n| `compilerOptions` | TypeScript CompilerOptions | A TypeScript [Compiler Options](https://www.typescriptlang.org/tsconfig) record. Note: If a Program is passed, this option will be ignored.                                                       |\n\n## Optimization\n\nEven though DI-Compiler is built for speed, there are ways you can speed it up significantly.\n\n### Optimization 1: Activate `preserveValueImports` in your tsconfig CompilerOptions\n\nBy default, TypeScript will discard imported bindings of value types that are unused.\nThis means that the following example:\n\n```ts\nimport {Foo} from \"./foo\";\ncontainer.registerSingleton\u003cFoo\u003e();\n```\n\nWould actually compile into code that would crash on runtime:\n\n```js\n// Error: Foo is not defined\ncontainer.registerSingleton(undefined, {identifier: \"Foo\", implementation: Foo});\n```\n\nTo work around this, DI-Compiler has to track the imports of the files, _and_ add them back\nin after transpilation, which comes at a cost.\n\nYou can optimize this by activating the `preserveValueImports` option in your tsconfig:\n\n```json\n{\n\t\"compilerOptions\": {\n\t\t\"preserveValueImports\": true\n\t}\n}\n```\n\nBy doing that, you instruct TypeScript to leave unused value imports be. DI-Compiler will recognize\nthis and opt out of all the internal logic for adding imported bindings back in.\n\n### Optimization 2: Pass in one or more identifiers to consider instances of DIContainer instead of relying on partial evaluation\n\n\u003e Note: This optimization is irrelevant if a Typescript Program is passed to DI-Compiler.\n\nAs [described here](#usage-as-an-api), it may not always be possible to statically infer whether or not an identifier is in fact an instance of [DIContainer](https://github.com/wessberg/di) when DI-Compiler does not have access to a Typechecker.\nOr, it may simply be slow, in case a lot of Nodes have to be visited in order to determine it.\n\nTo make it more robust and much faster simultaneously, pass in one or more identifiers as the `identifier` option that should be considered instances of DIContainer:\n\n```ts\nimport {di, transform} from \"@wessberg/di-compiler\";\n\n// Example when using the transform function\ntransform(\n\t`\\\n\timport {container} from \"./services\";\n\tcontainer.get\u003cFoo\u003e();\n`,\n\t{\n\t\t// Treat identifiers named `container` as instances of DIContainer\n\t\tidentifier: \"container\"\n\t}\n);\n```\n\nSee [this section](#customizing-di-compiler-when-used-as-a-loader) for details on how to pass the option when DI-Compiler is used as a loader.\n\n\u003c!-- SHADOW_SECTION_CONTRIBUTING_START --\u003e\n\n## Contributing\n\nDo you want to contribute? Awesome! Please follow [these recommendations](./CONTRIBUTING.md).\n\n\u003c!-- SHADOW_SECTION_CONTRIBUTING_END --\u003e\n\n\u003c!-- SHADOW_SECTION_MAINTAINERS_START --\u003e\n\n\u003c!-- SHADOW_SECTION_MAINTAINERS_END --\u003e\n\n\u003c!-- SHADOW_SECTION_FAQ_START --\u003e\n\n## FAQ\n\n\u003c!-- SHADOW_SECTION_FAQ_END --\u003e\n\n#### DI-Compiler doesn't correctly update all my calls to the DIContainer methods\n\nIf you pass a Program to DI-Compiler (such as you typically do when you use it as a Custom Transformer), this means that the Typechecker wasn't able to determine that one or more identifiers in your\ncode was in fact instances of DIContainer. Please verify that TypeScript correctly tracks the type of the objects on which you invoke the relevant DIContainer methods.\n\nIf you _don't_ pass a Program to DI-Compiler, then you're relying on DI-Compiler being able to statically infer whether or not identifiers are instances of DIContainer without having access to multiple files\ninside your application. This will very often lead to problems if you reference an instance of DIContainer from another file inside your application. To fix it, pass one or more identifiers that should be\nconsidered instances of DIContainer as an option. Please see [this section](#optimization-2-pass-in-one-or-more-identifiers-to-consider-instances-of-dicontainer-instead-of-relying-on-partial-evaluation) for details\non how you can do that.\n\n#### How does it work, exactly?\n\nFirst, classes that are discovered as part of your Typescript program/bundle will be parsed for their constructor argument types and positions.\nThen, instances of the [DIContainer](https://github.com/wessberg/di) will be discovered and their expressions will be upgraded.\nFor example, an expression such as:\n\n```typescript\nimport {DIContainer} from \"@wessberg/di\";\nimport {MyInterface} from \"./my-interface.js\";\nimport {MyImplementation} from \"./my-implementation.js\";\n\nconst container = new DIContainer();\ncontainer.registerSingleton\u003cMyInterface, MyImplementation\u003e();\n```\n\nWill be compiled into:\n\n```javascript\n// ...\ncontainer.registerSingleton(undefined, {\n\tidentifier: `MyInterface`,\n\timplementation: MyImplementation\n});\n```\n\n\u003c!-- SHADOW_SECTION_LICENSE_START --\u003e\n\n## License\n\nMIT ©\n\n\u003c!-- SHADOW_SECTION_LICENSE_END --\u003e\n","funding_links":["https://github.com/sponsors/wessberg","https://patreon.com/wessberg","https://www.patreon.com/bePatron?u=11315442"],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwessberg%2FDI-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwessberg%2FDI-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwessberg%2FDI-compiler/lists"}