# sloth-ts-injection

> Sloth Dependency Injection For Typescript

Latest version **1.0.0** (published 2019-01-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install sloth-ts-injection
pnpm add sloth-ts-injection
yarn add sloth-ts-injection
bun add sloth-ts-injection
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-01-23 |
| First published | 2019-01-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 75.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ImOverlord |
| Maintainers | imoverlord |

## Links

- npm: https://www.npmjs.com/package/sloth-ts-injection
- Repository: https://github.com/ImOverlord/sloth-ts-injection
- Homepage: https://github.com/ImOverlord/sloth-ts-injection#readme
- Issues: https://github.com/ImOverlord/sloth-ts-injection/issues
- npm.io page: https://npm.io/package/sloth-ts-injection

## Dependencies (1)

- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.12

## Recent versions

- 1.0.0 (latest) — 2019-01-23
- 1.1.0 (beta) — 2019-03-14

## README

# sloth-ts-injection

[![Build Status](https://travis-ci.org/ImOverlord/sloth-ts-injection.svg?branch=master)](https://travis-ci.org/ImOverlord/sloth-ts-injection)
[![Coverage Status](https://coveralls.io/repos/github/ImOverlord/sloth-ts-injection/badge.svg?branch=master)](https://coveralls.io/github/ImOverlord/sloth-ts-injection?branch=master)


Sloth Dependency Injection For Typescript

## Installation

You can get the latest release and the type definitions using npm:

```
$ npm install sloth-ts-injection reflect-metadata --save
```

> /!\\ sloth-ts-injection requires TypeScript >= 2.0, your tsconfig should look similar to the one below (experimentalDecorators, emitDecoratorMetadata are important)
```js
{
    "compilerOptions": {
        "target": "es5",
        "lib": ["es6"],
        "types": ["reflect-metadata"],
        "module": "commonjs",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true
    }
}
```

## Getting Started

You can declare dependencies with @slothInject() decorator.

```ts
import { slothInject } from 'sloth-ts-injection';

@slothInject()
export class DependencyA {
    public data: number = 0;
}
```

You can then require this dependency.

```ts
import { slothInject } from 'sloth-ts-injection';
import { DependencyA } from "./dependencyA";

@slothInject()
export class DependencyD {

    constructor(public a: DependencyA   ) { }

    public update() {
        this.a.data++;
    }
}
```

sloth-ts-injection will resolve the dependencies needed for you

```ts
import { Injector } from 'sloth-ts-injection';

const injector = new Injector();
const dep: DependencyD = injector.inject(DependencyD);

dep.update();
```

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