C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

  • Routing
  • Controllers
  • API Resources
  • Dependency Injection
  • Service Providers
  • Middleware
  • Request & Response
  • Authentication
  • Validation
  • Session
  • I18n
  • Utilities
Architecture

Service Providers

The central place to configure your application. Service providers allow you to register bindings, event listeners, middleware, and more.

Registration

Bind services into the service container.

Bootstrapping

Configure services after all bindings are registered.

Lazy Loading

Providers are loaded efficiently during application startup.

Writing a Provider

Extend the ServiceProvider class and implement the register and boot methods.

providers/StorageServiceProvider.ts
1import { ServiceProvider, container } from "canxjs";
2import { S3Client } from "@aws-sdk/client-s3";
3
4export class StorageServiceProvider extends ServiceProvider {
5 /**
6 * Register bindings in the container.
7 */
8 async register() {
9 container.bind("STORAGE_CLIENT", () => {
10 return new S3Client({ region: "us-east-1" });
11 });
12 }
13
14 /**
15 * Bootstrap any application services.
16 */
17 async boot() {
18 // Perform actions after all providers are registered
19 }
20}

Registering Providers

Add your providers to the createApp configuration.

app.ts
1import { createApp } from "canxjs";
2import { StorageServiceProvider } from "./providers/StorageServiceProvider";
3
4const app = createApp({
5 providers: [
6 StorageServiceProvider
7 ]
8});

Next Steps

Deep dive into the IOC Container.