Dependency Injection

Use platform-managed FHIR, HTTP, cache, metrics, support, and configuration services.

The script runtime completes dependency and property injection before onStartup(), so injected services are ready during script initialization and throughout the script lifecycle.

Injection is available only in the main integration script

FireSonic performs dependency injection only for the main script that implements IntegrationScript. Helper classes under scripts/core/ are not injection targets. Pass any required runtime services from Main.groovy to helper classes explicitly.

Injected services and configuration

AnnotationInjected typePurpose
@InjectFhirFhirClientFHIR searches, transactions, terminology translation and advanced FHIR access.
@InjectCacheScriptCacheFactoryTTL, singleton and refreshing caches.
@InjectMetricsScriptMetricsMetrics for additional script-side FHIR operations.
@InjectSupportScriptSupportRetry, sleep/backoff and chunking utilities.
@InjectHttpScriptHttpClientFactoryNamed, platform-managed HTTP clients for non-FHIR REST integrations.
@ScriptPropertyString / boolean / Set / Map / …Configuration values from script.properties.

Example

class Main implements IntegrationScript {

    @InjectFhir
    FhirClient fhir

    @InjectSupport
    ScriptSupport support

    @InjectCache
    ScriptCacheFactory caches

    @InjectMetrics
    ScriptMetrics metrics

    @InjectHttp
    ScriptHttpClientFactory httpClientFactory

    @ScriptProperty("hospitalName")
    String hospitalName

    // lifecycle hooks ...
}

Service lifetime

Within the main IntegrationScript implementation, injected services remain available through onStartup(), shouldProcess(), preConvert(), postConvert(), postValidation(), and onShutdown() for the active script generation.

Reuse runtime-managed services

Do not manually instantiate FhirClient, ScriptSupport, ScriptCacheFactory, or HTTP client factories. Use the instances supplied by the SDK/runtime and reuse them across hook invocations.

Troubleshooting injection

If an injected field is unexpectedly null, first confirm that the field belongs to the main script implementing IntegrationScript. Then verify the annotation, field type and import statements, and confirm that the script is being loaded through the FireSonic SDK/runtime rather than executed as a standalone Groovy script.