# @totemish/injector

> Dependency-free dependency injection for TypeScript and JavaScript that just works.

Latest version **1.0.0** (published 2018-02-09) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @totemish/injector
pnpm add @totemish/injector
yarn add @totemish/injector
bun add @totemish/injector
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-02-09 |
| First published | 2018-02-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 79.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | priestine |
| Maintainers | priestine |
| Keywords | totemish, container, di, dependency, injection, typescript |

## Links

- npm: https://www.npmjs.com/package/@totemish/injector
- Repository: https://github.com/totemish/injector
- Homepage: https://github.com/totemish/injector#readme
- Issues: https://github.com/totemish/injector/issues
- npm.io page: https://npm.io/package/@totemish/injector

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-02-09

## README

# Injector

[![Core Build Status](https://travis-ci.org/totemish/injector.svg?branch=master)](https://travis-ci.org/totemish/injector)
[![codecov](https://img.shields.io/codecov/c/github/totemish/injector.svg)](https://codecov.io/gh/totemish/injector)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![downloads](https://img.shields.io/npm/dm/packages/@totemish/injector.svg)](https://www.npmjs.com/package/@totemish/injector)
[![version](https://img.shields.io/npm/v/@totemish/injector.svg)](https://www.npmjs.com/package/@totemish/injector)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()

Totemish Injector brings a simple approach to dependency injection. Simply decorate what you mean
to be injectable with `@Injectable()` and then `@Inject()` it where it needs to be in place. Your
injectable will be available right in the constructor.

Totemish Injector is dependency free and does no automagic for you so that you don't end up having
weird behaviour and fat metadata.

## Installation

```bash
npm i --save @totemish/injector
```

## Usage

There are two main ways you can set and get an injectable. The first one for both is to use
decorators.

* `@Injectable(name?)` allows you to mark code that you want to be injectable in other parts of your
code. You can provide an optional `name` argument and it will override the default name of the
injectable (by default, it is the class name). If you do so, you won't be able to refer to the
injectable via its class reference and you will always have to pass the name you've specified.

* `@Inject(...names)` allows injecting one or multiple injectables marked with `@Injectable`.
You will be able to get them via the constructor of the class that has the `@Inject` decorator.
If you have multiple injectables for a class, follow the same order you provide them to `@Inject`.
This rule is quite easy to follow yet saves us from lots of extra code.

##### Example

```typescript
import { Injectable, Inject, InjectableInterface } from '@totemish/injector';

@Injectable()
export class Mouth {
  public say(phrase: string): void {
    console.log(`${phrase}!`);
  }
}

/**
 * You can give specific names for services if you need to. Those names are generated even
 * if you don't provide them, they just use the class name, like with the Mouth class
 */
@Injectable('thoughtfulness')
export class Brain {
  public getCleverThought(): string {
    return 'Polymorphism is when Gammy bears go polygamy';
  }
}

@Inject('thoughtfulness', Mouth)
export class Human {
  public constructor(private brain: Brain, private mouth: Mouth) {}
  
  public saySomethingClever() {
    this.mouth.say(this.brain.getCleverThought());
  }
}
```

## Links

* [API](https://totemish.github.io/framework)
* [Docs (Under Construction)](https://totemish.com/docs)
* [Tutorials (Under Construction)](https://totemish.com/tutorials)
* [Sample App (Under Construction)](https://github.com/totemish/sample-app)

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