Registry / observability / inversify-logger-middleware

inversify-logger-middleware

JSON →
library3.1.0jsnpmunverified

inversify-logger-middleware is a specialized middleware designed to integrate with InversifyJS, providing a console-based logger for visualizing the dependency injection resolution plan. It intercepts the binding and resolution process within an InversifyJS container, displaying a detailed tree-like structure of service identifiers, bindings, implementation types, scopes, and target metadata. This tool is invaluable for debugging complex dependency graphs and understanding how InversifyJS resolves dependencies. The current stable version is 3.1.0, which is compatible with `inversify@3.x.x`. Its release cadence is tightly coupled with major InversifyJS releases to ensure compatibility. Key differentiators include its deep integration with InversifyJS internals and its clear, visual representation of the container's resolution logic, which helps developers quickly identify misconfigurations or unexpected dependency flows.

npm install inversify-logger-middleware
INSTALL
IMPORT
SIG · INVERSIFY-LOGGER-M
I
inversify-logger-middleware
observabilityjavascriptv3.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

makeLoggerMiddleware
import { makeLoggerMiddleware } from 'inversify-logger-middleware';
const makeLoggerMiddleware = require('inversify-logger-middleware');
Primary factory function to create the middleware. InversifyJS and its ecosystem are primarily TypeScript/ESM-first, though CommonJS usage is possible with appropriate transpilation.
Container
import { Container, ContainerModule } from 'inversify';
import { Container } from 'inversify-logger-middleware';
Container and related types (like ContainerModule) are part of the core 'inversify' package, not the logger middleware itself.
interfaces.Bind
import { interfaces } from 'inversify';
import { Bind } from 'inversify-logger-middleware';
Binding interfaces are exported from the core 'inversify' package.

This quickstart demonstrates how to set up an InversifyJS container with conditional bindings, apply the logger middleware, and resolve dependencies, showing the detailed resolution plan in the console.

import "reflect-metadata"; import { Container, ContainerModule, interfaces } from 'inversify'; import { makeLoggerMiddleware } from 'inversify-logger-middleware'; interface Weapon { attack(): string; } interface Warrior { fight(): string; sneak(): string; } class Katana implements Weapon { public attack() { return "cut!"; } } class Shuriken implements Weapon { public attack() { return "throw!"; } } class Samurai implements Warrior { private _weapon: Weapon; constructor(@inversify.inject("Weapon") weapon: Weapon) { this._weapon = weapon; } public fight() { return this._weapon.attack(); } public sneak() { return ""; } } class Ninja implements Warrior { private _weapon: Weapon; constructor(@inversify.inject("Weapon") weapon: Weapon) { this._weapon = weapon; } public fight() { return this._weapon.attack(); } public sneak() { return "sneak!"; } } const container = new Container(); const logger = makeLoggerMiddleware(); container.applyMiddleware(logger); const warriorModule = new ContainerModule((bind: interfaces.Bind) => { bind<Weapon>("Weapon").to(Katana).whenInjectedInto(Samurai); bind<Weapon>("Weapon").to(Shuriken).whenInjectedInto(Ninja); bind<Warrior>("Warrior").to(Samurai).whenTargetTagged("canSneak", false); bind<Warrior>("Warrior").to(Ninja).whenTargetTagged("canSneak", true); }); container.load(warriorModule); // This will now log the resolution plan to the console const ninja = container.getTagged<Warrior>("Warrior", "canSneak", true); console.log(ninja.fight()); console.log(ninja.sneak()); const samurai = container.getTagged<Warrior>("Warrior", "canSneak", false); console.log(samurai.fight());
Debug
Known issues
breakingVersion 3.0.0 introduced breaking changes to align with InversifyJS v3.0.0. Ensure your core 'inversify' package is also updated to v3.x.x for compatibility.
fix
Update 'inversify' to a compatible 3.x.x version. Consult the InversifyJS v3 migration guide if upgrading from an older major version.
affects: >=3.0.0
breakingVersion 2.0.0 of inversify-logger-middleware is compatible with inversify@2.0.0. Major version bumps typically indicate breaking changes aligning with the core InversifyJS library's API changes.
fix
Ensure your 'inversify' dependency matches the major version required by inversify-logger-middleware. For v2.x.x of the logger, use inversify@2.x.x.
affects: >=2.0.0 <3.0.0
gotchaThis package requires TypeScript 2.0 or higher for its type definitions. Using an older TypeScript version may result in compilation errors related to missing types or incorrect type inference.
fix
Upgrade your project's TypeScript version to 2.0 or newer. Ensure 'skipLibCheck' is not masking issues if you are encountering unexpected type problems.
affects: >=1.0.0
Errors
Common errors & fixes
Error: No matching bindings found for serviceIdentifier: Symbol(Weapon)
The logger middleware cannot resolve bindings that are not correctly configured in the InversifyJS container.
fix
Review your `ContainerModule` or direct `bind` calls to ensure that all requested service identifiers have at least one valid binding. Check for typos in service identifiers or incorrect `when` clauses.
TypeError: container.applyMiddleware is not a function
You might be using an older version of InversifyJS that does not support the `applyMiddleware` method, or `container` is not an instance of `Inversify.Container`.
fix
Update your `inversify` package to a version that supports middleware (e.g., 2.0.0 or higher). Ensure that the `container` variable is indeed a `new Container()` instance.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies
inversifyrequiredCore dependency injection framework.
reflect-metadatarequiredRequired by InversifyJS for decorator metadata reflection.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
inversify-logger-middleware — npm install inversify-logger-middleware · libregistry