> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-framework/module-development/capabilities/services.md).

# Services

{% hint style="warning" %}
Services require **Java**. There is no BoxLang-only mechanism for registering global runtime services.
{% endhint %}

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`

```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`

```
ortus.boxlang.modules.mymodule.services.MyService
```

## Accessing Services

Once registered, your service can be accessed via:

```java
// From Java
MyService service = (MyService) BoxRuntime.getInstance()
    .getGlobalService( Key.of( "MyService" ) );
```

```js
// From BoxLang
var service = boxRuntime.getGlobalService( "MyService" )
```

## 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

{% hint style="info" %}
Services are registered during module registration and activated during module activation. See [Lifecycle](/boxlang-framework/module-development/lifecycle.md) for details.
{% endhint %}

## Next Steps

* [Schedulers](/boxlang-framework/module-development/capabilities/schedulers.md) — Scheduled task management (Java only)
* [Cache Providers](/boxlang-framework/module-development/capabilities/cache-providers.md) — Custom caching backends (Java only)
* [JDBC Drivers](/boxlang-framework/module-development/capabilities/jdbc-drivers.md) — Database driver registration (Java only)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-framework/module-development/capabilities/services.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
