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

@onr/inversify-binding

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onr/inversify-binding

inversify module library

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
0
Created
Source

inversify-binding

inversify di library easy use

no need to reimport reflect-metadata

Usage

please check inversify see how to create module

import { inject, injectable } from 'inversify';
import { createContainerModule, createCoreContainer } from '../src/index';

const keyA = 'serviceA';
const keyB = 'serviceB';
interface IServiceA {
  getString(): string;
}

interface IServiceB {
  getString(): string;
  getStringFromA(): string;
}

@injectable()
class serviceA implements IServiceA {
  getString() {
    return 'serviceA';
  }
}

@injectable()
class serviceB implements IServiceB {
  @inject(keyA)
  private _serviceA!: serviceA;
  getString() {
    return 'serviceB';
  }
  getStringFromA() {
    return this._serviceA.getString();
  }
}

const coreContainer = createCoreContainer()
// nextjs page a using this
const serviceAModule = createContainerModule([keyA, serviceA])
// nextjs page b using this
const serviceBModule = createContainerModule([keyA, serviceA], [keyB, serviceB])
  • Why splitting serviceAModule and serviceBModule but both of them import serviceA?

make this can be easily code splitting in nextjs, then each page can inject the service module and avoid the repeated import.

load module

coreContainer.load(serviceAModule);
coreContainer.load(serviceBModule);

How to use in react component?

please check inversify-react

FAQs

Package last updated on 02 Sep 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