Netpress Laravel-inspired backend framework for Node.js
Frameworkv0.1.14 Starterv0.1.12 Docsv1.0.3
Overview Installation Architecture CLI
Architecture

Service Container

The service container lets the package resolve app-level services without hard-coding your project files. It is small, but it covers the common cases you need in a starter kit.

Quick Example

import { container } from "@admicaa/netpress";
import MailService from "../app/Services/MailService.js";

container.bind("mail", MailService);

const mail = container.get("mail");

Explanation

Bindings live behind a string key. You can bind a ready value or a lazy factory. The first time you call container.get(key), NetPress resolves the binding and caches it.

This pattern is used by the base mail and job classes:

  • BaseMail resolves the mail binding
  • BaseJob resolves queue.connection
  • the application kernel binds log and logger to the shared logger helper

Additional Examples

Bind queue configuration:

import { container } from "@admicaa/netpress";

container.bind("queue.connection", {
  host: "127.0.0.1",
  port: 6379,
});

Use a lazy factory when setup is expensive:

container.bind("search", () => {
  return new SearchClient(process.env.SEARCH_URL);
});

Advanced Usage

Keep bindings inside service providers when possible. That gives you one place to manage boot order and one place to test app setup.

Notes / Tips

  • Use stable keys like mail, queue.connection, and payments.gateway.
  • Bind once during boot.
  • Resolve from the container inside framework-facing code, not everywhere in the app.