
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@contextjs/di
Advanced tools
Object-oriented dependency injection for TypeScript — class-based, extensible, and transformer-powered.
A TypeScript-first, object-oriented dependency injection container with interface support, zero decorators, and full transformer-based resolution.
String, Number, etc.)onResolve hooknpm i @contextjs/di
Jump to: API Reference • Advanced Features • Philosophy • Testing
interface ILogger {
log(message: string): void;
}
class ConsoleLogger implements ILogger {
log(message: string) {
console.log('[LOG]', message);
}
}
import { ServiceCollection } from '@contextjs/di';
const services = new ServiceCollection();
services.addSingleton<ILogger, ConsoleLogger>();
const logger = services.resolve<ILogger>();
logger?.log('Hello from DI!');
import '@contextjs/di';
import { Application } from '@contextjs/system';
interface ILogger {
log(message: string): void;
}
class ConsoleLogger implements ILogger {
log(message: string) {
console.log('[LOG]', message);
}
}
const application = new Application();
application.useDependencyInjection();
application.services.addTransient<ILogger, ConsoleLogger>();
application.onRun(async () => {
const logger = application.services.resolve<ILogger>();
logger?.log('Application is running with dependency injection!');
});
await application.runAsync();
Acts as the container that stores service registrations and resolves instances.
The transformer compiles your registration call into metadata so that interfaces can be resolved automatically, with no need for runtime tokens or reflection.
services.addSingleton<IInterface, Implementation>();
services.resolve<IInterface>();
Detects loops and throws a CircularDependencyException with a readable chain trace.
If a dependency isn't registered but exists on globalThis (e.g. String, Number), it will attempt to instantiate it directly.
onResolveControl resolution at runtime (e.g. for scoped or per-request lifetimes):
services.onResolve = ({ name, lifetime, service }) => {
if (lifetime === 'scoped') {
return requestScope.getOrCreate(name, () => new service.type());
}
return null;
};
services.dependenciesAccessor.set('ILogger', {
lifetime: 'singleton',
type: ConsoleLogger,
parameters: []
});
This project maintains 100% test coverage across:
globalThis fallbackonResolve overridesMany DI containers in the JS/TS ecosystem rely on decorators and metadata reflection. These approaches are fragile, hard to test, and incompatible with interface-based architecture.
@contextjs/di takes a different path:
For detailed API documentation, please refer to the API Reference.
FAQs
Object-oriented dependency injection for TypeScript — class-based, extensible, and transformer-powered.
We found that @contextjs/di demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.