MCPcopy Index your code
hub / github.com/typestack/typedi

github.com/typestack/typedi @v0.10.0 sqlite

repository ↗ · DeepWiki ↗ · release v0.10.0 ↗
353 symbols 742 edges 111 files 16 documented · 5% 15 cross-repo links
README

TypeDI

Build Status codecov npm version Dependency Status

TypeDI is a dependency injection tool for TypeScript and JavaScript. With it you can build well-structured and easily testable applications in Node or in the browser.

Main features includes:

  • property based injection
  • constructor based injection
  • singleton and transient services
  • support for multiple DI containers

Installation

Note: This installation guide is for usage with TypeScript, if you wish to use TypeDI without Typescript please read the documentation about how get started.

To start using TypeDI install the required packages via NPM:

npm install typedi reflect-metadata

Import the reflect-metadata package at the first line of your application:

import 'reflect-metadata';

// Your other imports and initialization code
// comes here after you imported the reflect-metadata package!

As a last step, you need to enable emitting decorator metadata in your Typescript config. Add these two lines to your tsconfig.json file under the compilerOptions key:

"emitDecoratorMetadata": true,
"experimentalDecorators": true,

Now you are ready to use TypeDI with Typescript!

Basic Usage

import { Container, Service } from 'typedi';

@Service()
class ExampleInjectedService {
  printMessage() {
    console.log('I am alive!');
  }
}

@Service()
class ExampleService {
  constructor(
    // because we annotated ExampleInjectedService with the @Service()
    // decorator TypeDI will automatically inject an instance of
    // ExampleInjectedService here when the ExampleService class is requested
    // from TypeDI.
    private injectedService: ExampleInjectedService
  ) {}
}

const serviceInstance = Container.get(ExampleService);
// we request an instance of ExampleService from TypeDI

serviceInstance.injectedService.printMessage();
// logs "I am alive!" to the console

Documentation

The detailed usage guide and API documentation for the project can be found:

Contributing

Please read our contributing guidelines to get started.

Extension points exported contracts — how you extend this code

Factory (Interface)
(no doc) [23 implementers]
sample/sample12-array-values/Factory.ts
Factory (Interface)
(no doc) [23 implementers]
sample/sample5-named-services/Factory.ts
Store (Interface)
(no doc) [7 implementers]
sample/sample8-tokenized-services/Store.ts
Factory (Interface)
(no doc) [20 implementers]
test/github-issues/42/issue-42.spec.ts
LoggerInterface (Interface)
(no doc) [4 implementers]
sample/sample9-custom-decorator/LoggerInterface.ts
Car (Interface)
(no doc) [3 implementers]
test/decorators/Inject.spec.ts
Vehicle (Interface)
(no doc) [2 implementers]
test/Container.spec.ts
Handler (Interface)
(no doc)
src/interfaces/handler.interface.ts

Core symbols most depended-on inside this repo

get
called by 148
src/container.class.ts
Service
called by 100
src/decorators/service.decorator.ts
log
called by 42
sample/sample9-custom-decorator/LoggerInterface.ts
set
called by 36
src/container.class.ts
reset
called by 24
src/container.class.ts
Inject
called by 24
src/decorators/inject.decorator.ts
create
called by 16
test/github-issues/42/issue-42.spec.ts
of
called by 14
src/container.class.ts

Shape

Class 207
Method 124
Interface 12
Function 10

Languages

TypeScript100%

Modules by API surface

test/Container.spec.ts34 symbols
test/decorators/Service.spec.ts20 symbols
test/decorators/Inject.spec.ts20 symbols
src/container-instance.class.ts16 symbols
src/container.class.ts11 symbols
test/github-issues/151/issue-151.spect.ts9 symbols
test/github-issues/41/issue-41.spec.ts8 symbols
test/github-issues/87/issue-87.spec.ts7 symbols
test/github-issues/53/issue-53.spec.ts7 symbols
test/github-issues/102/issue-102.spec.ts7 symbols
test/github-issues/56/issue-56.spec.ts6 symbols
test/eager-loading-services.spec.ts6 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

@rollup/plugin-commonjs17.0.0 · 1×
@rollup/plugin-node-resolve11.0.1 · 1×
@types/jest26.0.20 · 1×
@types/node14.14.21 · 1×
@typescript-eslint/eslint-plugin3.7.1 · 1×
eslint7.17.0 · 1×
eslint-plugin-jest24.1.3 · 1×
husky4.3.7 · 1×
jest26.6.3 · 1×
lint-staged10.5.3 · 1×

For agents

$ claude mcp add typedi \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact