New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pequehq/di

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pequehq/di

IoC container for TypeScript and JavaScript applications.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-50%
Maintainers
2
Weekly downloads
 
Created
Source

Peque DI

coverage

Peque DI is an IoC container for TypeScript and JavaScript applications.

Install

npm install @pequehq/di reflect-metadata

Note: tsconfig's compilerOptions must have both experimentalDecorators and emitDecoratorMetadata set to true.

Example

import { Container, Injectable } from '@pequehq/di';

// Decorate with @Injectable() classes to be set to the IoC container.

@Injectable()
class Foo {
  getPizza() {
    return 'pizza';
  }
}

@Injectable()
class Bar {
  constructor(private foo: Foo) {}
  
  test() {
    console.log(this.foo.getPizza())
  }
}

@Injectable()
class Counter {
  #counter = 0;

  count() {
    this.#counter++;
    return this.#counter;
  }
}

// Create a container. This const can be exported to easily access the container across other project files.

const DI = new Container();

// Use `set` to bind injectable classes to the container.

DI.set(Foo, 'Foo'); // The default scope is being a singleton.
DI.set(Bar, 'Bar'); // The default scope is being a singleton.
DI.set(Counter, 'Counter').nonSingleton(); // The scope will be set to not be a singleton.

// Retrieve class instances with `get` (or using constructor properties).

DI.get<Bar>('Bar').test(); // logs "pizza"

Keywords

FAQs

Package last updated on 23 Feb 2022

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