The central place to configure your application. Service providers allow you to register bindings, event listeners, middleware, and more.
Bind services into the service container.
Configure services after all bindings are registered.
Providers are loaded efficiently during application startup.
Extend the ServiceProvider class and implement the register and boot methods.
1import { ServiceProvider, container } from "canxjs";2import { S3Client } from "@aws-sdk/client-s3";34export class StorageServiceProvider extends ServiceProvider {5/**6* Register bindings in the container.7*/8async register() {9container.bind("STORAGE_CLIENT", () => {10return new S3Client({ region: "us-east-1" });11});12}1314/**15* Bootstrap any application services.16*/17async boot() {18// Perform actions after all providers are registered19}20}
Add your providers to the createApp configuration.
1import { createApp } from "canxjs";2import { StorageServiceProvider } from "./providers/StorageServiceProvider";34const app = createApp({5providers: [6StorageServiceProvider7]8});