DependencyV1 Description Copyright (c) 2025 Mark Brennand, released under MIT License . Class defining the external Dependency API. Dependencies can be injected into an application by their interface or abstract class. Variable and member variable values can also be injected into a class using the variable's class and an action. An optional action argument is supported to allow for the binding of the same interface or class with different implementations. By default, the implementation created when injected will be a singleton. If the binding is required to create a new implementation for each use an application, the implementing class should implement the Prototype interface. All bound Types are stored in a registry. Each bound Type must have a BindingCheck implementation associated with it. To associate the Type with the BindingCheck, create and deploy a BindingCheck__mdt metadata record. Any attempt to add a binding to the registry for a Type with no associated BindingCheck will throw an Exception. See README for full details of the Dependency Injection API. Author Mark Brennand
Methods global static void bind(final
Type forType, final
Type withImpl)
Description Adds a binding to the registry. Parameter forType: The type to be bound. Must be either an interface or abstract class. Parameter withImpl: The implementation for the type and action. Must be a concrete class with a no-op constructor.
global static void bind(final
Type forType, final
String action, final
Type withImpl)
Description Adds a binding to the registry. Parameter forType: The type to be bound. Must be either an interface or abstract class. Parameter action: The action used in combination with the type to uniquely identify the binding. Parameter withImpl: The implementation for the type and action. Must be a concrete class with a no-op constructor.
global static Object inject(final
Type forType)
Description If the registry contains a binding for the given type, its implementation is returned. Should no binding exist, an exception is thrown. Parameter forType: The type to be bound. Returns The implementation of the given type.
global static Object inject(final
Type forType, final
String action)
Description If the registry contains a binding for the given type and action, its implementation is returned. Should no binding exist, an exception is thrown. Parameter forType: The type to be bound. Parameter action: The action specific to the binding to be bound. Returns The implementation of the given type.
Description Returns true if registry contains a binding for the given type and action, false if not. Parameter forType: The type to be checked. Returns True if binding exists, false if not.
Description Returns true if registry contains a binding for the given type and action, false if not. Parameter forType: The type to be checked. Parameter action: The action specific to the binding to be checked. Returns True if binding exists, false if not.
global static void reload()
Description Forces the custom bindings to be reloaded.
DependencyV1.ValidationResult global with sharing class ValidationResult
Description Class representing result of a binding validation check.
Methods global ValidationResult(final
Boolean isValid, final
String errorMessage)
Description Constructs a validation result object which is used to inform the caller of the BindingCheck.validate method of the result of the validation. Parameter isValid: True if the validation passed. False if not. Parameter errorMessage: The error message to be recorded in the Exception thrown to record the failure.
DependencyV1.BindingCheck global interface BindingCheck
Description Interface to be implemented to check a binding in the registry. Each checker must be defined in a record in the Binding Check custom metadata.
Methods ValidationResult validate(
Type forType,
Type withImpl)
Description Given a type to be bound, a class implementing this method must check that the given implementation class can be bound to it. If the for type is an interface then an implementation of this method must check that the implementation class implements the interface. If the for type is an abstract class then an implementation of this method must check that the implementation class extends the abstract class. If the for type is a class then an implementation of this method must check that the implementation class is of the same class or a super class of it. Parameter forType: The type to be bound. Parameter withImpl: The implementation to bind to the type. Returns The result of the validation.