@orieljs/container
v0.1.0-alpha.13
Published
The Oriel IoC container: bindings, request scopes and inject().
Readme
@orieljs/container
The Oriel service container: bindings, singletons, request scopes and inject(). It follows Laravel's Illuminate\Container. The container is part of @orieljs/framework, which every Oriel app already installs, and is re-exported from it. In an app, import it from @orieljs/framework; @orieljs/container is also published on its own.
npm install @orieljs/framework// @filename: app/Services/Geocoder.ts
export class Geocoder {
constructor(readonly apiKey: string) {}
}
// ---cut---
import { config, ServiceProvider } from '@orieljs/framework'
import { Geocoder } from '../Services/Geocoder'
export class AppServiceProvider extends ServiceProvider {
override register(): void {
this.app.singleton(Geocoder, () => new Geocoder(config<string>('services.geocoder.key')))
}
}bind(), singleton(), scoped() and instance() register a class or a token, and make() resolves it. inject(Geocoder) resolves from the current container anywhere in a request, and a scoped() binding gets one instance per request.
Documentation: https://orieljs.vercel.app/docs/container
Status: early alpha. APIs will change.
License
Oriel is open-source software licensed under the Apache License 2.0 (Apache-2.0; see LICENSE and NOTICE). The Oriel name and logo are trademarks; see TRADEMARKS.md.
Website: https://orieljs.vercel.app
