Skip to content

@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 ​

ExportMirrorsNotes
Containerthe usual designbind/singleton/instance/make/build/alias/bound/forget/flush, tagging (tag/tagged), contextual binding (when().needs().give())
Configthe usual designdot-path get/set/has/merge/all
parseDotenv / envthe .env loader + env()parse .env content; coerce true/false/null/empty/numbers
ServiceProviderthe usual designasync-capable register() + boot()
ApplicationFoundation\Applicationa Container that owns config + the provider lifecycle
Facade / createFacadefacades (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')

Released under the MIT License.