Class ContextInjector
java.lang.Object
com.cloudforgeci.api.core.annotation.ContextInjector
Standalone utility for injecting context values into annotated fields.
This allows any class (not just BaseFactory subclasses) to use the
@DeploymentContext, @SystemContext, and
@SecurityProfileConfiguration annotations for dependency injection.
Slot Auto-Extraction
When a @SystemContext field references a Slot, the injector automatically extracts
the value from the Slot. No need for manual .get().orElseThrow() calls!
Usage examples:
public class MyCustomClass {
// Simple context value injection
@DeploymentContext("region")
private String region;
// Direct field injection (non-Slot)
@SystemContext("security")
private SecurityProfile security;
// Automatic Slot extraction - no .get().orElseThrow() needed!
@SystemContext("alb")
private IApplicationLoadBalancer alb; // Auto-extracted from ctx.alb Slot
@SystemContext("vpc")
private Vpc vpc; // Auto-extracted from ctx.vpc Slot
public MyCustomClass(Construct scope) {
// Inject all annotated fields
ContextInjector.inject(this, scope);
}
}
Error Handling
If a Slot is empty when accessed, a clear error message indicates which resource is missing and reminds you to create it first.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidinject(Object target, SystemContext systemContext, DeploymentContext deploymentContext) Inject context values into all annotated fields of the given object.static voidInject context values into all annotated fields of the given object.
-
Method Details
-
inject
Inject context values into all annotated fields of the given object.- Parameters:
target- The object whose fields should be injectedscope- The CDK construct scope to retrieve context from
-
inject
public static void inject(Object target, SystemContext systemContext, DeploymentContext deploymentContext) Inject context values into all annotated fields of the given object.- Parameters:
target- The object whose fields should be injectedsystemContext- The SystemContext to inject fromdeploymentContext- The DeploymentContext to inject from
-