Socket
Book a DemoInstallSign in
Socket

@rym-lib/inversify-bundler

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rym-lib/inversify-bundler

Bundle `ContainerModule` for [inversify](https://github.com/inversify/InversifyJS). Co-located module bundling solution.

latest
npmnpm
Version
1.4.3
Version published
Weekly downloads
292
-43.85%
Maintainers
1
Weekly downloads
 
Created
Source

@rym-lib/inversify-bundler

Bundle ContainerModule for inversify. Co-located module bundling solution.

installation

npm i -D @rym-lib/inversify-bundler

Usage

Module creation

interface ExamplePort {}

@injectable()
class Example implements ExamplePort {
  constructor(
    @inject(DBIdentifier)
    private db: DBPort,
  ) {}
}

const { identifier: ExampleIdentifier, bundler: ExampleModule } =
  createModule<ExamplePort>('Example', Example, [DBModule])

export { ExampleIdentifier, ExampleModule }
export type { ExamplePort }

Bundling modules

import { ExampleModule, ExamplePort, ExampleIdentifier } from './example'

const container = new Container()
container.load(...ExampleModule.resolve())

const example = container.get<ExamplePort>(ExampleIdentifier)

createModule<Interface>(name: string, Module: Newable<Interface>, bindings: ModuleInput[])

const { identifier, bundler } = createModule<InteractionPort>(
  'UserRegister',
  UserRegisterInteraction,
  [PrismaModule, LoggerModule],
)

new ModuleBundler(...modules: ModuleInput[])

import { ContainerModule as InversifyContainerModule } from 'inversify'

import { ContainerModule, ModuleBundler } from '@rym-lib/inversify-bundler'

import { LoggerModule } from '~/logger'
import { prisma } from '~/my-prisma'

const name = 'Prisma'
const prismaIdentifier = Symbol.for(name)

const redisIdentifier = Symbol.for('Redis')

const bundler = new Bundler(
  LoggerModule,
  new ContainerModule(
    (bind) => {
      bind<PrismaPort>(prismaIdentifier).toDynamicValue(() => prisma)
    },
    { name },
  ),
  new InversifyContainerModule((bind) => {
    bind<RedisPort>(redisIdentifier).toDynamicValue(() => redis)
  }),
)

resolve module

resolve() exclude duplicate module and return flat ContainerModule array. But, can not resolve in already registered container's modules. Use child container.

import { Container } from 'inversify'

import { bundler } from '~/my-module'

const container = new Container()

container.load(...bundler.resolve())

FAQs

Package last updated on 12 Sep 2025

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