# typedi

> Dependency injection for TypeScript.

Latest version **0.10.0** (published 2021-01-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install typedi
pnpm add typedi
yarn add typedi
bun add typedi
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.10.0 |
| Published | 2021-01-15 |
| First published | 2015-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 422.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4244 |
| Author | TypeStack contributors |
| Maintainers | pleerock, nonameprovided, typestack-release-bot |

## Links

- npm: https://www.npmjs.com/package/typedi
- Repository: https://github.com/pleerock/typedi
- Homepage: https://github.com/pleerock/typedi#readme
- Issues: https://github.com/pleerock/typedi/issues
- npm.io page: https://npm.io/package/typedi

## Recent versions

- 0.10.0 (latest) — 2021-01-15
- 0.9.1 — 2021-01-11
- 0.9.0 — 2021-01-10
- 0.8.0 — 2018-06-21
- 0.7.3 — 2018-05-08
- 0.7.2 — 2018-03-27
- 0.7.1 — 2018-02-27
- 0.7.0 — 2018-02-22
- 0.6.1 — 2018-02-06
- 0.6.0 — 2017-11-24
- 0.5.2 — 2017-05-10
- 0.5.1 — 2017-04-24
- 0.5.0 — 2017-04-19
- 0.4.3 — 2016-12-25
- 0.4.2 — 2016-07-14
- … 11 more at https://npm.io/package/typedi/versions

## README

# TypeDI

![Build Status](https://github.com/typestack/typedi/workflows/CI/badge.svg)
[![codecov](https://codecov.io/gh/typestack/typedi/branch/master/graph/badge.svg)](https://codecov.io/gh/typestack/typedi)
[![npm version](https://badge.fury.io/js/typedi.svg)](https://badge.fury.io/js/typedi)
[![Dependency Status](https://david-dm.org/typestack/typedi.svg)](https://david-dm.org/typestack/typedi)

TypeDI is a [dependency injection](https://en.wikipedia.org/wiki/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:

```bash
npm install typedi reflect-metadata
```

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

```ts
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:

```json
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
```

Now you are ready to use TypeDI with Typescript!

## Basic Usage

```ts
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:

- at [docs.typestack.community/typedi][docs-stable]
- in the `./docs` folder of the repository

[docs-stable]: https://docs.typestack.community/typedi/
[docs-development]: https://docs.typestack.community/typedi/v/develop/

## Contributing

Please read our [contributing guidelines](./CONTRIBUTING.md) to get started.

---
_Source: https://npm.io/package/typedi · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
