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.
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
| Annotation | Injected type | Purpose |
|---|---|---|
@InjectFhir | FhirClient | FHIR searches, transactions, terminology translation and advanced FHIR access. |
@InjectCache | ScriptCacheFactory | TTL, singleton and refreshing caches. |
@InjectMetrics | ScriptMetrics | Metrics for additional script-side FHIR operations. |
@InjectSupport | ScriptSupport | Retry, sleep/backoff and chunking utilities. |
@InjectHttp | ScriptHttpClientFactory | Named, platform-managed HTTP clients for non-FHIR REST integrations. |
@ScriptProperty | String / 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.
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.
