# try-di

> [![Build Status](https://travis-ci.com/AVykhrystyuk/try-di.svg?branch=master)](https://travis-ci.com/AVykhrystyuk/try-di) [![Coverage Status](https://coveralls.io/repos/github/AVykhrystyuk/try-di/badge.svg)](https://coveralls.io/github/AVykhrystyuk/try-di

Latest version **1.0.0** (published 2021-09-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install try-di
pnpm add try-di
yarn add try-di
bun add try-di
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-09-22 |
| First published | 2021-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 105.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alexey Vykhrystyuk |
| Maintainers | avykhrystyuk |
| Keywords | dependency injection container, dependency, injection, container, di container, di, ioc, injector |

## Links

- npm: https://www.npmjs.com/package/try-di
- Repository: https://github.com/AVykhrystyuk/try-di
- Homepage: https://github.com/AVykhrystyuk/try-di#readme
- Issues: https://github.com/AVykhrystyuk/try-di/issues
- npm.io page: https://npm.io/package/try-di

## 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) — 2021-09-22

## README

# try-di

[![Build Status](https://travis-ci.com/AVykhrystyuk/try-di.svg?branch=master)](https://travis-ci.com/AVykhrystyuk/try-di)
[![Coverage Status](https://coveralls.io/repos/github/AVykhrystyuk/try-di/badge.svg)](https://coveralls.io/github/AVykhrystyuk/try-di)

Try DI is a simple, typesafe and lightweight dependency injection container for TypeScript. Designed with the idea to avoid having runtime errors due to missing, incorrect or outdated mapping configuration.

- **Safe.** It type-checks every mapping. Allows to verify all the mappings on CI.
- **Fast.** `TODO: need to measure a sample`
- **Simple.** It supports the minimum required and sufficient functionality for most apps.
- **Small.** 828 bytes (minified and gzipped). No dependencies.
  [Size Limit] controls the size.

```js
import { createContainer } from 'try-di';

const container = createContainer();

container
  .useValue({ for: Water, use: new Water() })
  .useValue({ for: Fish, use: new Fish() })
  .useFactory({ for: Milk, use: (r) => new Milk(r.resolve(Water)) })
  .useClass({ for: Animal, use: Cat, inject: [Fish, Milk] });

assert.ok(container.resolve(Cat).isCat, "Cat wasn't resolved");
```

Supports modern browsers, IE and Node.js. Provides modern ES2019 and CommonJS bundles, as well as legacy ones (ES5).

[size limit]: https://github.com/ai/size-limit

`TODO: more samples - how to verifyAll() and all possible ways to register deps`

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