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

@zcodeapp/di

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zcodeapp/di

Dependency Injection

latest
Source
npmnpm
Version
0.3.5
Version published
Maintainers
0
Created
Source

Di - Dependency Injection

Di CI codecov

Overview

This module provides a lightweight and efficient implementation of dependency injection (DI) in TypeScript. It consists of three main components: Di (Dependency Injection container), Inject (decorator for dependency injection), and Injectable (decorator to mark a class as available for injection).

Features

  • Dependency Injection Container (Di): A centralized system to manage application dependencies, facilitating the creation and retrieval of service instances.
  • Inject Decorator: Enables declarative dependency injection in classes, enhancing readability and keeping the code clean.
  • Injectable Decorator: Marks a class as "injectable," making it manageable by the DI container. This simplifies the registration and resolution of dependencies.
  • Instance Lifecycle Management: The module may offer control over the lifecycle of created instances, like singleton or request-scoped instances.
  • Seamless TypeScript Integration: Designed to work seamlessly with TypeScript, providing strong typing and decorator support.
  • Flexibility and Extensibility: Capable of adapting to various use cases and easily extendable to cater to specific project requirements.
  • Enhanced Testability: Facilitates unit testing by allowing easy mock and stub integration, leading to more maintainable and testable code.

Installation

Include the Di class in your TypeScript project:

npm install @zcodeapp/di

Usage

First, import the Di class and other necessary interfaces:

import { Di } from "@zcodeapp/di";
import { Example } from "example"

const di = Di.getInstance();
di.register(Example);
const instance = di.get(Example);

API Reference

Di The core of the DI system, responsible for creating and managing instances.

Inject A decorator used to inject dependencies into a class.

Injectable A decorator that marks a class as injectable, allowing it to be managed by the Di container.

Example

Here's a basic example of how to use the DI module:

import { Di, Injectable, Inject } from "@zcodeapp/di";

@Injectable()
class DependencyClass {}

@Injectable()
class ConsumerClass {
  constructor(private dependency: DependencyClass) {}
}

const di = Di.getInstance();
const instance = di.get(ConsumerClass);

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

dependency

FAQs

Package last updated on 23 Jun 2024

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