Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dependency-inject

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dependency-inject

> [Live Demo](https://jsfiddle.net/yp90Lep9/15/)

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

DependencyInject

Live Demo

import { Container, inject } from 'dependency-inject'

class Store {
    num = 1
}

class Action {
    @inject(Store)
    private store: Store

    setNum(num: number) {
        this.store.num = num
    }
}

// init store
const container = new Container()
container.set(Store, new Store())
container.set(Action, new Action())

// get data with injected
const store = container.get(Store)
const action = container.get(Action)

action.setNum(2)
console.log(store.num) // 2

Simple useage by injectFactory

import { injectFactory } from 'dependency-inject'
class Store {
    num = 1
}

class Action {
    @inject(Store)
    private store: Store

    setNum(num: number) {
        this.store.num = num
    }
}

const stores = injectFactory({Store, Action})
// stores.Store.num === 1
// stores.Action.setNum

nested object

import { injectFactory } from 'dependency-inject'
class Store {
    num = 1
}

class Action {
    @inject(Store)
    private store: Store

    setNum(num: number) {
        this.store.num = num
    }
}

const stores = injectFactory({
    groupA: Store,
    groupB: {
        groupC: Action
    }
})

FAQs

Package last updated on 03 Dec 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc