Skip to main content
This release is 2 versions behind 0.2.1 — the latest version of @findhow/container. Jump to latest

Built and signed on GitHub Actions

Wasn't a fan of using decorators to dependency inject things in the TypeScript world. Now you don't have to.

This package works with Node.js, DenoIt is unknown whether this package works with Cloudflare Workers, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
100%
Published
a week ago (0.1.0)
class Container
implements LaravelContainer

The Container class implements the LaravelContainer interface and provides a dependency injection container for managing class dependencies and performing dependency injection.

Constructors

new
Container()

Properties

Methods

private
addCallbackToMap(
abstract: Bindable,
callback: Function,
): void
addContextualBinding(
concrete: Abstract,
abstract: Abstract,
implementation: Function | Abstract,
): void

Add a contextual binding to the container.

afterResolving(
abstract: Bindable,
callback: Function,
): void
alias(
abstract: Abstract,
alias: string,
): void

Alias a type to a different name.

beforeResolving(
abstract: Bindable,
callback: Function,
): void
bind(
abstract: Abstract,
concrete?: Function | Abstract,
shared?: boolean,
): void

Register a binding with the container.

bindIf(
abstract: Abstract,
concrete?: Function | Abstract,
shared?: boolean,
): void
bindMethod(
method: string | [string, string],
callback: Function,
): void

Determine if the given abstract type has been bound.

call(
callback: Function | string,
parameters?: Bindable[],
defaultMethod?: string,
): any

Call the given function / class method and inject its dependencies.

createInstance<T>(constructor: new (...args: any[]) => T): T
extend(
abstract: Abstract,
closure: Function,
): void

Extend an abstract type in the container.

Get a closure to resolve the given type from the container.

flush(): void

Flush all of the container's bindings.

instance(
abstract: Abstract,
instance: any,
): void

Register an existing instance as shared in the container.

make(
abstract: Abstract,
parameters?: Bindable[],
): any

Resolve the given type from the container.

register<T>(
constructor: Constructor<T>,
paramTypes: (Bindable | Bindable[])[],
): void

Register a class and its dependencies with the container.

private
resolve(abstract: Abstract): any
resolving(
abstract: Bindable,
callback: Function,
): void
private
runAfterResolvingCallbacks(
abstract: Abstract,
instance: any,
): void
private
runBeforeResolvingCallbacks(abstract: Abstract): void
private
runCallbacks(
abstract: Abstract,
instance?: any,
): void
private
runResolvingCallbacks(
abstract: Abstract,
instance: any,
): void
scoped(
abstract: Abstract,
concrete?: Function | Abstract,
): void

Register a scoped binding in the container.

scopedIf(
abstract: Abstract,
concrete?: Function | Abstract,
): void

Register a scoped binding if it hasn't already been registered.

singleton(
abstract: Abstract,
concrete?: Function | Abstract,
): void

Register a shared binding in the container.

singletonIf(
abstract: Abstract,
concrete?: Function | Abstract,
): void

Register a shared binding if it hasn't already been registered.

tag(
abstracts: Abstract | Abstract[],
tags: string | string[],
): void

Assign a set of tags to a given abstract type(s).

tagged(tag: string): any[]

Resolve all of the bindings for a given tag.

Define a contextual binding.

Add Package

deno add jsr:@findhow/container

Import symbol

import { Container } from "@findhow/container/container";

---- OR ----

Import directly with a jsr specifier

import { Container } from "jsr:@findhow/container/container";

Add Package

npx jsr add @findhow/container

Import symbol

import { Container } from "@findhow/container/container";

Add Package

yarn dlx jsr add @findhow/container

Import symbol

import { Container } from "@findhow/container/container";

Add Package

pnpm dlx jsr add @findhow/container

Import symbol

import { Container } from "@findhow/container/container";

Add Package

bunx jsr add @findhow/container

Import symbol

import { Container } from "@findhow/container/container";