@plinthjs/core
The kernel of Plinth: the service container, configuration, service providers, the application lifecycle, and facades. Depends only on @plinthjs/support.
Phased container (see ADR-0001). This package ships the container surface - a conventional API - as a standalone IoC. It is backed by / bridged to NestJS's DI at the Tier-3 HTTP integration point. Nest remains the runtime bet; this only sequences when it's adopted.
What's here
| Export | Mirrors | Notes |
|---|---|---|
Container | the usual design | bind/singleton/instance/make/build/alias/bound/forget/flush, tagging (tag/tagged), contextual binding (when().needs().give()) |
Config | the usual design | dot-path get/set/has/merge/all |
parseDotenv / env | the .env loader + env() | parse .env content; coerce true/false/null/empty/numbers |
ServiceProvider | the usual design | async-capable register() + boot() |
Application | Foundation\Application | a Container that owns config + the provider lifecycle |
Facade / createFacade | facades (ADR-0005) | Proxy-backed static-call layer; Facade.swap() for test fakes |
Identifiers are string/symbol tokens or class constructors. JS has no reflection-based autowiring, so dependencies are wired through factory functions (or build with explicit args).
Usage
ts
import { Application, ServiceProvider, Facade, createFacade } from '@plinthjs/core'
class CacheProvider extends ServiceProvider {
register() {
this.app.singleton('cache', () => new Map())
}
}
const app = new Application({ config: { app: { name: 'Plinth' } } })
await app.bootstrapWith([CacheProvider])
// DI (recommended):
const cache = app.make<Map<string, unknown>>('cache')
// Facade (fidelity):
Facade.setContainer(app)
const Cache = createFacade<Map<string, unknown>>('cache')
Cache.set('framework', app.config.get('app.name'))Contextual binding
ts
app.when('photos').needs('disk').give('disk.local')
app.when('videos').needs('disk').give('disk.s3')