For the complete documentation index, see llms.txt. This page is also available as Markdown.

Services

Register global runtime services in your BoxLang module (Java only)

Global services extend the BoxLang runtime with persistent, singleton functionality available across the entire application lifecycle.

Creating a Service

Implement the IService interface and register via ServiceLoader:

File: src/main/java/ortus/boxlang/modules/mymodule/services/MyService.java

import ortus.boxlang.runtime.services.IService;
import ortus.boxlang.runtime.BoxRuntime;
import ortus.boxlang.runtime.scopes.Key;

public class MyService implements IService {

    @Override
    public Key getName() {
        return Key.of( "MyService" );
    }

    @Override
    public void onStartup( BoxRuntime runtime ) {
        System.out.println( "MyService started!" );
    }

    @Override
    public void onShutdown( Boolean force ) {
        System.out.println( "MyService shutting down!" );
    }

    @Override
    public void onConfigurationLoad() {
        // Called when configuration is loaded
    }
}

ServiceLoader Config: src/main/resources/META-INF/services/ortus.boxlang.runtime.services.IService

Accessing Services

Once registered, your service can be accessed via:

Service Lifecycle

Services follow the same lifecycle as the runtime:

  1. onConfigurationLoad() — Called when boxlang.json is loaded

  2. onStartup() — Called when the runtime starts

  3. onShutdown() — Called when the runtime shuts down

Services are registered during module registration and activated during module activation. See Lifecycle for details.

Next Steps

  • Schedulers — Scheduled task management (Java only)

  • Cache Providers — Custom caching backends (Java only)

  • JDBC Drivers — Database driver registration (Java only)

Last updated

Was this helpful?