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:
BaseMailresolves themailbindingBaseJobresolvesqueue.connection- the application kernel binds
logandloggerto 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, andpayments.gateway. - Bind once during boot.
- Resolve from the container inside framework-facing code, not everywhere in the app.