Class ContextInjector

java.lang.Object
com.cloudforgeci.api.core.annotation.ContextInjector

public final class ContextInjector extends Object
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 Details

    • inject

      public static void inject(Object target, software.constructs.Construct scope)
      Inject context values into all annotated fields of the given object.
      Parameters:
      target - The object whose fields should be injected
      scope - 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 injected
      systemContext - The SystemContext to inject from
      deploymentContext - The DeploymentContext to inject from