# @csejtei/simple-container

> Simple dependency injection container

Latest version **1.0.3** (published 2020-04-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @csejtei/simple-container
pnpm add @csejtei/simple-container
yarn add @csejtei/simple-container
bun add @csejtei/simple-container
```

## 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.3 |
| Published | 2020-04-23 |
| First published | 2020-04-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dávid Csejtei |
| Maintainers | csejtei |

## Links

- npm: https://www.npmjs.com/package/@csejtei/simple-container
- Repository: https://github.com/davidcsejtei/simple-container
- Homepage: https://github.com/davidcsejtei/simple-container#readme
- Issues: https://github.com/davidcsejtei/simple-container/issues
- npm.io page: https://npm.io/package/@csejtei/simple-container

## Recent versions

- 1.0.3 (latest) — 2020-04-23
- 1.0.2 — 2020-04-22
- 1.0.1 — 2020-04-22
- 1.0.0 — 2020-04-22

## README

# Simple Dependency Injection Container

![typescript](https://badgen.net/badge/icon/typescript?icon=typescript&label)

## Install
```typescript
npm i @csejtei/simple-container
```

## Usage

Use container in your controllers:
- pass a container through the constructor
- get any injectable item (= dependency) (e.g.: a service) from the container
- use injected service anywhere in the controller

Imagine the following example: You have a UserController which is using your custom UserService service, you can inject userService with the Container

```typescript
import { Container } from '@csejtei/simple-container';
import UserService from '../services/UserService';

class UserController {
    userService: UserService;

    constructor(container: Container) {
        this.userService = container.get(UserService);
    }

    generateUserHash(salt) {
        return this.userService.generateHash(salt);
    }
}
```

Your UserService has to implement **Injectable**:

```typescript
class UserService implement Injectable {
    // generateHash ...etc
}
```

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