Data & Services

Framework services

Use the service container, providers, events, cache, filesystem, hashing, and encryption.

Beta · v0.2.0Lanjit APIs may change before the stable release. Review the release notes and upgrade guide before updating.

Bindings may be transient, singleton, existing instances, or aliases. Providers register services and run boot logic after registration. Built-in services include database, memory cache, events, filesystem access rooted at storage/app, structured logging, sessions, rate limiting, authentication, authorization, hashing, encryption, queueing, and scheduling.

Examples

app.bind('billing', (app) => new BillingService(app.make('db')));
app.singleton('metrics', () => new MetricsClient());
app.instance('release', '0.2.0');
app.alias('database', 'db');

const billing = app.make('billing');
import { ServiceProvider } from '../../framework/Foundation/ServiceProvider.js';

export class BillingServiceProvider extends ServiceProvider {
  register() {
    this.app.singleton('billing', (app) => new BillingService(app.make('db')));
  }

  async boot() {
    // Daftarkan listener atau lakukan bootstrap tambahan.
  }
}
app.make('events').listen('user.registered', async (user) => {
  await sendWelcomeEmail(user);
});

await app.make('events').dispatch('user.registered', user);
const users = await app.make('cache').remember('users.active', 60, () => {
  return User.query().where('active', true).get();
});

app.make('cache').forget('users.active');
app.make('cache').flush();
app.make('log').info('Invoice created', { invoiceId: 10 });
await app.make('files').put('report.txt', 'Selesai');
const encrypted = app.make('crypt').encrypt({ token: 'sensitive' });
const original = app.make('crypt').decrypt(encrypted);
Edit this page on GitHub

Type to search all documentation.