| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A universal, lightweight and type-safe dependency injection container for TypeScript. Heavily inspired by Angular's DI system, but designed to work in any environment (Node.js, Bun, Deno, browsers, and more).
Please check out the migration guide for details on what's new and how to upgrade from v1.
npm install @illuma/coreInstall the bundled Agent Skill so your AI coding agent follows Illuma's conventions:
npx skills add git-illuma/coreThe skill lives at skills/illuma-core/ and is installed into your project's agent directory (e.g. .claude/skills/).
ES2020+. In practice: Node.js 14+, Bun, Deno, and browsers from early 2020 onwards (Chrome 80+, Firefox 74+, Safari 13.1+).
That is a checked floor rather than an aspiration. The npm bundle is pinned to it (target: 'es2020'), and the sources are written to it too, so the JSR package — which publishes src/ rather than the bundle — asks no more of you than npm does.
| Requirement | Level | Why |
|---|---|---|
| globalThis | ES2020 | Read at module scope, to key shared state by symbol so two copies of the library interoperate |
| Optional chaining, ?? | ES2020 | Throughout |
| WeakRef, FinalizationRegistry | ES2021 | Only for weakParentLink, and only when you opt in |
Two notes:
import { NodeContainer, NodeInjectable, nodeInject } from '@illuma/core';
@NodeInjectable()
class Logger {
public log(message: string) {
console.log(`[LOG]: ${message}`);
}
}
@NodeInjectable()
class UserService {
private readonly logger = nodeInject(Logger);
public getUser(id: string) {
this.logger.log(`Fetching user ${id}`);
return { id, name: 'John Doe' };
}
}
const container = new NodeContainer();
container.provide([Logger, UserService]);
container.bootstrap();
const userService = container.get(UserService);Note: Example above requires experimentalDecorators and emitDecoratorMetadata in tsconfig. See Getting Started for decorator-free alternatives.
import { NodeToken, MultiNodeToken, NodeContainer } from '@illuma/core';
// Single-value token
const CONFIG = new NodeToken<{ apiUrl: string }>('CONFIG');
// Multi-value token (when injected, returns array)
const PLUGINS = new MultiNodeToken<Plugin>('PLUGINS');
const container = new NodeContainer();
container.provide([
// Equivalent to:
// { provide: CONFIG, value: { apiUrl: 'https://api.example.com' } }
CONFIG.withValue({ apiUrl: 'https://api.example.com' }),
// Equivalent to:
// { provide: PLUGINS, useClass: AnalyticsPlugin }
PLUGINS.withClass(AnalyticsPlugin),
// Equivalent to:
// { provide: PLUGINS, useClass: LoggingPlugin }
PLUGINS.withClass(LoggingPlugin),
]);
container.bootstrap();
const config = container.get(CONFIG); // { apiUrl: string }
const plugins = container.get(PLUGINS); // Plugin[]: [AnalyticsPlugin, LoggingPlugin]See Tokens Guide for more details.
// Class provider
container.provide(MyService);
// Value provider
container.provide({ provide: CONFIG, value: { apiUrl: '...' } });
// Factory provider
container.provide({ provide: DATABASE, factory: () => {
// You can use nodeInject inside factories!
const env = nodeInject(ENV);
return createDatabase(env.connectionString);
} });
// Class provider with custom implementation
container.provide({ provide: DATABASE, useClass: DatabaseImplementation });
// Alias provider
container.provide({ provide: Database, alias: ExistingDatabase });See Providers Guide for details.
import { createTestFactory } from '@illuma/core/testkit';
const createTest = createTestFactory({
target: UserService,
provide: [{ provide: Logger, useClass: MockLogger }],
});
it('should fetch user', () => {
const { instance } = createTest();
expect(instance.getUser('123')).toBeDefined();
});See Testing Guide for examples.
| Guide | Description |
|---|---|
| Getting Started | Installation, setup, and basic usage |
| Providers | Value, factory, class, and alias providers |
| Tokens | NodeToken and MultiNodeToken |
| Async Injection | Lazy loading and sub-containers |
| Lifecycle Hooks | Container destruction and lifecycle hooks |
| Testing | TestKit and mocking |
| Plugins | Extending Illuma with custom scanners and diagnostics |
| Technical Overview | Deep dive into how Illuma works |
| API Reference | Complete API documentation |
| Troubleshooting | Error codes and solutions |
Illuma supports plugins! Check these out:
See Plugins Guide for creating your own plugins.
Thank you for considering contributing to Illuma! I deeply appreciate your interest in making this project better.
Anyways, to get you started, please take a look at the Contributing Guide for guidelines on how to setup development environment, run tests, and submit pull requests.
MIT
Created by bebrasmell
| Back | FazBrowse Home | New Git URL |