New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

ttdi

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ttdi

![GitHub](https://img.shields.io/github/license/Luncher/ttdi?style=for-the-badge) ![npm](https://img.shields.io/npm/v/ttdi?style=for-the-badge) ![Travis (.com)](https://img.shields.io/travis/com/Luncher/ttdi?style=for-the-badge)

latest
Source
npmnpm
Version
1.0.6
Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

ttdi

GitHub npm Travis (.com)

ttdi is a dependency injection tool for TypeScript and JavaScript.

features:

  • property based injection
  • constructor based injection
  • support for multiple DI containers
  • auto collection providers(injectable)

Quick Start

Prerequisite

ttdi leverage decorator and metadata, you need to enable emitting decorator metadata in your Typescript config.Add these two lines to your tsconfig.json file under the compilerOptions key:

"emitDecoratorMetadata": true,
"experimentalDecorators": true,

For the decorator of TypeScript, please refer to decorators

Install

yarn add ttdi -S

or

npm i ttdi -S

Usage

declare.ts

import { Inject, Injectable } from 'ttdi'

@Injectable()
export class Bar {
  constructor() {

  }
}

@Injectable()
export class Baz {

}

@Injectable()
export class Foo {
  @Inject
  baz!: Baz
  constructor(public bar: Bar) {}
}

main.ts

import { configure, Container } from 'ttdi'
import { Bar, Baz, Foo } from './declare'

const container = new Container()
await configure(container, __dirname + '/declare.ts')
const foo = container.get(Foo)

expect(foo).toBeInstanceOf(Foo)
expect(foo.bar).toBeInstanceOf(Bar)
expect(foo.baz).toBeInstanceOf(Baz)

API

@Injectable()

The tag class can be injected as a provider.

@Inject()

class property inject.

notice: constructor argument will auto injected.

configure

a async providers(injectable) loader.

container

instance storage container, you can create multi DI containers.

FAQs

Package last updated on 29 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts