variable-container-module.ts 1.1 KB

12345678910111213141516171819202122232425262728
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { ContainerModule } from 'inversify';
  6. import { VariableEngine } from './variable-engine';
  7. import { VariableFieldKeyRenameService } from './services';
  8. import { ContainerProvider, VariableEngineProvider } from './providers';
  9. import { ASTRegisters } from './ast';
  10. /**
  11. * An InversifyJS container module that binds all the necessary services for the variable engine.
  12. * This module sets up the dependency injection for the core components of the variable engine.
  13. */
  14. export const VariableContainerModule = new ContainerModule((bind) => {
  15. bind(VariableEngine).toSelf().inSingletonScope();
  16. bind(ASTRegisters).toSelf().inSingletonScope();
  17. bind(VariableFieldKeyRenameService).toSelf().inSingletonScope();
  18. // Provide a dynamic provider for VariableEngine to prevent circular dependencies.
  19. bind(VariableEngineProvider).toDynamicValue((ctx) => () => ctx.container.get(VariableEngine));
  20. // Provide a ContainerProvider to allow AST nodes and other components to access the container.
  21. bind(ContainerProvider).toDynamicValue((ctx) => () => ctx.container);
  22. });