Core Package
Service Providers (Core)
Service providers are the central place for configuring your LaraNode application.
Service Providers (Core)
Service providers are the central place for configuring your LaraNode application.
Overview
Service providers handle:
- Registering services in the IoC container
- Booting services after registration
- Registering middleware
- Accessing configuration
The ServiceProvider Class
import { ServiceProvider } from "@lara-node/core";
export class AppServiceProvider extends ServiceProvider {
register() {
// Bind services
}
boot() {
// Boot services
}
}
The app Property
Access the container via this.app:
export class AppServiceProvider extends ServiceProvider {
register() {
this.app.singleton(UserService, () => {
return new UserService(this.app.make(DatabaseService));
});
}
boot() {
const service = this.app.make(UserService);
service.initialize();
}
}
Middleware Helpers
registerMiddleware()
Register middleware aliases:
export class HttpMiddlewareProvider extends MiddlewareServiceProvider {
registerMiddleware() {
return {
aliases: {
auth: AuthMiddleware,
throttle: ThrottleMiddleware,
},
groups: {
api: ["auth", "throttle"],
},
priority: ["throttle"],
};
}
}
Configuration Access
Access config in providers:
boot() {
const dbConfig = this.app.config('database')
const cacheDriver = this.app.config('cache.driver')
}
Lifecycle
1. app.register(Provider)
└─ Provider.register()
2. app.boot()
├─ Provider.booting() callbacks
├─ Provider.boot()
└─ Provider.booted() callbacks
Next Steps
- Application -- Application class
- Container -- IoC container
- Guide: Service Providers -- Full guide
Form Request
The FormRequest is a Laravel-inspired request validation class that encapsulates validation logic, authorization, and input handling into a single, type-safe class. When type-hinted in a controller method, the router automatically instantiates it, runs validation, and injects it — returning a 422 response on failure.
Database Package
The @lara-node/db package provides a Laravel Eloquent-inspired ORM with support for MySQL and MongoDB, migrations, seeders, traits, and observers.