di-framework
A lightweight, type-safe dependency injection framework for TypeScript, plus companion packages for common application concerns. The core automatically manages service instantiation, dependency resolution, and lifecycle management.
Published docs at docs.di-framework.dev include a header version switcher (versions.json) so you can open /latest/ or a frozen /vX.Y/ snapshot from a release tag. In-page search is scoped to the snapshot you are reading.
Features
Zero Dependencies: No external dependencies required. Works with SWC and TypeScript's native decorator support.
Type-Safe: Full TypeScript support with type inference for all injected dependencies.
Automatic Resolution: Dependencies are automatically resolved and injected.
Lifecycle Management: Built-in support for singleton and transient service lifecycles.
Factory Functions: Register services using factory functions for complex initialization.
Event-Driven: Decouple service communication with
@Publisherand@Subscriberdecorators.Telemetry: Built-in support for method tracking and monitoring with
@Telemetryand@TelemetryListener.Error Detection: Detects circular dependencies and unregistered services at runtime.
Testing Support: Easy to test with mock service registration.
Repository Abstraction: Includes
@di-framework/repofor standardized data access, storage-agnostic repositories, and decorator/SQL/manifest database migrations.HTTP Routing & OpenAPI: Type-safe HTTP routing and build-time OpenAPI 3.1 generation with
@di-framework/http.GraphQL: Object-oriented, decorator-driven GraphQL with
@di-framework/graphql— domain classes become the schema.Events: Bridge
@Publisher/@Subscriberto Kafka, NATS, or in-memory transports with@di-framework/events.Configuration: Typed, validated config from env, JSON, YAML, and TOML files injected via DI with
@di-framework/config, including{profile}.config.{ext}overlays via@WithProfile.Authentication: Sessions, JWT, OAuth2/OIDC, and WebAuthn passkeys on WebCrypto with
@di-framework/auth— zero runtime dependencies.Resource Authorization: Decorator-authored policies, EBNF interchange, DI resource providers, and fail-closed HTTP controller bindings with
@di-framework/authz.Sockets: Security-first WebSocket, TCP, and UDP with a WebCrypto secure channel via
@di-framework/socket(network I/O — distinct from the in-process event bus).RPC: Decorator-generated JSON-RPC and per-method gRPC with a typed client via
@di-framework/rpc— the same service over memory, HTTP, sockets, and Connect / gRPC.Private service bindings:
@ExportService/@ServiceBindinggrant named in-process callers access to a contract without a URL or HTTP route.Scheduling:
@Cronruns DI-managed methods on a 5-field expression or millisecond interval; wasmCloud deployments disable in-process timers and apply Kubernetes CronJobs.Durable queues:
@di-framework/queuespersists jobs with at-least-once delivery, retries, and dead-letter inspection.Actors:
@di-framework/actorsprovides a local virtual-actor runtime with serialized mailboxes and typed references. No Wasm host is required for local use.AI: Annotation-driven chat, tools, RAG, MCP, and agents with
@di-framework/ai(OpenAI-compatible and Anthropic HTTP adapters). Agent Skills (SKILL.md), plugin discovery (.agents/plugins), and the skills toolbox live in@di-framework/ai-utils.Unified CLI:
di-frameworkis the only public executable for application, skills, HTTP, agent, and monorepo workflows.Runtime type checks:
ttsctransform@di-framework/tscinjects parameter guards from TypeScript types at emit time (di-framework initwires this by default).wasmCloud backing services: Tenant-scoped Redis/NATS provisioning through
BackingServicerequests, with protectedServiceBindingconfiguration and Kubernetes admission policies in 5.3.6. See backing services.WebAssembly deployment: Build WASI 0.3 HTTP components with the wasmCloud CLI extension and consume native service bindings. The kube platform provides a local cluster and live verification examples.
Why Use This Framework?
Traditional dependency injection requires manual service instantiation and wiring, which becomes error-prone and difficult to maintain as your application grows. This framework eliminates that complexity:
Without di-framework:
With di-framework:
Benefits:
No manual service instantiation
No manual dependency wiring
Automatic singleton management
Type-safe dependency resolution
Easier to test (mock services simply by registering test implementations)
Scales better as services grow
Quick Example
Next Steps
Installation - Set up the framework in your project
Quick Start - Learn the basics with simple examples
CLI - Complete command tree, output contract, and package ownership
Deployment - Cloud Foundry, wasmCloud, and local Kubernetes with di-framework-kube
Runtime type checks - Emit-time parameter guards (
@di-framework/tsc; wired byinit)HTTP Router - Type-safe routes and OpenAPI generation
GraphQL - Domain classes as a GraphQL schema
Events - Bridge container events to Kafka / NATS / memory
Sockets - WebSocket, TCP, UDP with a secure channel (
@di-framework/socket)RPC - JSON-RPC and per-method gRPC with a typed client (
@di-framework/rpc)Configuration - Typed config from env, JSON, YAML, and TOML via DI
Authentication - Sessions, JWT, OAuth2/OIDC, and passkeys
Resource Authorization - Declarative policies and HTTP resource enforcement
AI - Chat, tools, RAG, MCP, and agents with
@di-framework/aiAgent Skills -
SKILL.md, plugins, builders, and jailed tools in@di-framework/ai-utilsRepositories - Standardized data access with
@di-framework/repoAPI Reference - Complete API documentation
Advanced Usage - Learn advanced patterns and techniques