coldbox.system.ioc

Class Injector

lucee.Component
    extended by coldbox.system.ioc.Injector
All Implemented Interfaces:
IInjector

Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp www.ortussolutions.com --- The WireBox injector is the pivotal class in WireBox that performs dependency injection. It can be used standalone or it can be used in conjunction of a ColdBox application context. It can also be configured with a mapping configuration file called a binder, that can provide object/mappings and configuration data. A WireBox Injector: Builds the graphs of objects that make up your application. Easy Startup:

injector = new coldbox.system.ioc.Injector();
Binder Startup
injector = new coldbox.system.ioc.Injector(new MyBinder());
Binder Path Startup
injector = new coldbox.system.ioc.Injector( "config.MyBinder" );

Class Attributes:
  • synchronized : false
  •  
  • accessors : true
  •  
  • persistent : false
  •  
  • serializable : false
  •  
    Property Summary
    type property default serializable required
    any binder
          The Configuration Binder object.

    • access = public
    • returntype = any
    true false
    any cacheBox
          CacheBox Link.

    • access = public
    • returntype = any
    true false
    any coldbox
          ColdBox Application Link.

    • access = public
    • returntype = any
    true false
    any eventManager
          Event Manager Link.

    • access = public
    • returntype = any
    true false
    array eventStates
          Configured Event States.

    • access = public
    • returntype = any
    true false
    any injectorID
          The injector Unique ID.

    • access = public
    • returntype = any
    true false
    any javaSystem
          Java System.

    • access = public
    • returntype = any
    true false
    any log
          Log Reference.

    • access = public
    • returntype = any
    true false
    any logBox
          LogBox and Class Logger.

    • access = public
    • returntype = any
    true false
    any parent
          Parent Injector.

    • access = public
    • returntype = any
    true false
    any scopes
          LifeCycle Scopes.

    • access = public
    • returntype = any
    true false
    any scopeStorage
          Scope Storages Utility.

    • access = public
    • returntype = any
    true false
    any utility
          ColdBox Utility class.

    • access = public
    • returntype = any
    true false
    any version
          WireBox Version.

    • access = public
    • returntype = any
    true false
    Constructor Summary
    init([any binder='coldbox.system.ioc.config.DefaultBinder'], [struct properties='[runtime expression]'], [any<Controller> coldbox=''])
          Constructor.
    Method Summary
    any autowire(any target, [any<Mapping> mapping], [any targetID=''], [boolean annotationCheck='false'])
         I wire up target objects with dependencies either by mappings or a-la-carte autowires.
    private any buildBinder(any binder, any properties)
         Load a configuration binder object according to passed in type.
    any buildInstance(any<Mapping> mapping, [struct initArguments='[runtime expression]'])
         Build an instance, this is called from registered scopes only as they provide locking and transactions.
    Injector clearSingletons()
         Clear the singleton cache.
    Injector configure(any<Binder> binder, struct properties)
         Configure this injector for operation, called by the init().
    private Injector configureCacheBox(struct config)
         Configure a standalone version of cacheBox for persistence.
    private Injector configureEventManager()
         Configure a standalone version of a WireBox Event Manager.
    private Injector configureLogBox(any configPath)
         Configure a standalone version of logBox for logging.
    boolean containsInstance(any name)
         Checks if this injector can locate a model instance or not.
    private Injector doScopeRegistration()
         Register this injector on a user specified scope.
    string getBinder()
    string getCacheBox()
    string getColdbox()
    string getEventManager()
    string getEventStates()
    string getInjectorID()
    any getInstance([any name], [any dsl], [struct initArguments='[runtime expression]'], [any targetObject=''])
         Locates, Creates, Injects and Configures an object model instance.
    string getJavaSystem()
    string getLog()
    string getLogBox()
    any<BeanPopulator> getObjectPopulator()
         Get an object populator useful for populating objects from JSON,XML, etc.
    any<Injector> getParent()
         Get a reference to the parent injector instance, else an empty simple string meaning nothing is set.
    any getScope(any scope)
         Get a registered scope in this injector by name.
    struct getScopeRegistration()
         Get the structure of scope registration information.
    string getScopes()
    string getScopeStorage()
    any<Util> getUtil()
         Return the core util object.
    string getUtility()
    string getVersion()
    private Injector injectTarget(any target, any propertyName, any propertyObject, any scope, any argName)
         Inject a model object with dependencies via setters or property injections.
    boolean isCacheBoxLinked()
         Checks if CacheBox is linked.
    boolean isColdBoxLinked()
         Checks if Coldbox application context is linked.
    any locateInstance(any name)
         Tries to locate a specific instance by scanning all scan locations and returning the instantiation path.
    any<Injector> locateScopedSelf()
         Return a self reference using the scoped registration, mostly used by providers or scope widening objects.
    private Injector processAfterCompleteDI(any targetObject, any DICompleteMethods)
         Process after DI completion routines.
    private Injector processInjection(any targetObject, any DIData, any targetID)
         Process property and setter injection.
    private Injector processMixins(any targetObject, any mapping)
         Process mixins on the selected target.
    private Injector processProviderMethods(any targetObject, any mapping)
         Process provider methods on the selected target.
    Injector registerDSL(any namespace, any path)
         A direct way of registering custom DSL namespaces.
    Injector registerListener(any listener)
         Register all the configured listeners in the configuration file.
    private Injector registerListeners()
         Register all the configured listeners in the configuration file.
    any registerNewInstance(any name, any instancePath)
         Register a new requested mapping object instance thread safely and returns the mapping configured for this instance.
    private Injector registerScopes()
         Register all internal and configured WireBox Scopes.
    Injector removeFromScope()
         Remove the Injector from scope registration if enabled, else does nothing.
    any setBinder(any binder)
    any setCacheBox(any cacheBox)
    any setColdbox(any coldbox)
    any setEventManager(any eventManager)
    any setEventStates(array eventStates)
    any setInjectorID(any injectorID)
    any setJavaSystem(any javaSystem)
    any setLog(any log)
    any setLogBox(any logBox)
    any setParent(any<Injector> injector)
         Link a parent Injector with this injector.
    any setScopes(any scopes)
    any setScopeStorage(any scopeStorage)
    any setUtility(any utility)
    any setVersion(any version)
    any shutdown()
         Shutdown the injector gracefully by calling the shutdown events internally.
     
    Methods inherited from class lucee.Component
    None

    Constructor Detail

    init

    public init([any binder='coldbox.system.ioc.config.DefaultBinder'], [struct properties='[runtime expression]'], [any<Controller> coldbox=''])

    Constructor. If called without a configuration binder, then WireBox will instantiate the default configuration binder found in: coldbox.system.ioc.config.DefaultBinder

    Parameters:
    binder - The WireBox binder or data CFC instance or instantiation path to configure this injector with
    properties - A structure of binding properties to passthrough to the Binder Configuration CFC
    coldbox - A coldbox application context that this instance of WireBox can be linked to, if not using it, we just ignore it.

    Property Detail

    binder

    property any binder

    The Configuration Binder object

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    cacheBox

    property any cacheBox

    CacheBox Link

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    coldbox

    property any coldbox

    ColdBox Application Link

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    eventManager

    property any eventManager

    Event Manager Link

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    eventStates

    property array eventStates

    Configured Event States

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    injectorID

    property any injectorID

    The injector Unique ID

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    javaSystem

    property any javaSystem

    Java System

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    log

    property any log

    Log Reference

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    logBox

    property any logBox

    LogBox and Class Logger

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    parent

    property any parent

    Parent Injector

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    scopes

    property any scopes

    LifeCycle Scopes

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    scopeStorage

    property any scopeStorage

    Scope Storages Utility

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    utility

    property any utility

    ColdBox Utility class

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    version

    property any version

    WireBox Version

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    Method Detail

    autowire

    public any autowire(any target, [any<Mapping> mapping], [any targetID=''], [boolean annotationCheck='false'])

    I wire up target objects with dependencies either by mappings or a-la-carte autowires

    Parameters:
    target - The target object to wire up
    mapping - The object mapping with all the necessary wiring metadata. Usually passed by scopes and not a-la-carte autowires
    targetID - A unique identifier for this target to wire up. Usually a class path or file path should do. If none is passed we will get the id from the passed target via introspection but it will slow down the wiring
    annotationCheck - This value determines if we check if the target contains an autowire annotation in the cfcomponent tag: autowire=true|false, it will only autowire if that metadata attribute is set to true. The default is false, which will autowire anything automatically.

    buildBinder

    private any buildBinder(any binder, any properties)

    Load a configuration binder object according to passed in type

    Parameters:
    binder - The data CFC configuration instance, instantiation path or programmatic binder object to configure this injector with
    properties - A map of binding properties to passthrough to the Configuration CFC

    buildInstance

    public any buildInstance(any<Mapping> mapping, [struct initArguments='[runtime expression]'])

    Build an instance, this is called from registered scopes only as they provide locking and transactions

    Parameters:
    mapping - The mapping to construct
    initArguments - The constructor structure of arguments to passthrough when initializing the instance

    clearSingletons

    public Injector clearSingletons()

    Clear the singleton cache


    configure

    public Injector configure(any<Binder> binder, struct properties)

    Configure this injector for operation, called by the init(). You can also re-configure this injector programmatically, but it is not recommended.

    Parameters:
    binder - The configuration binder object or path to configure this Injector instance with
    properties - A structure of binding properties to passthrough to the Configuration CFC

    configureCacheBox

    private Injector configureCacheBox(struct config)

    Configure a standalone version of cacheBox for persistence

    Parameters:
    config - The cacheBox configuration data structure

    configureEventManager

    private Injector configureEventManager()

    Configure a standalone version of a WireBox Event Manager


    configureLogBox

    private Injector configureLogBox(any configPath)

    Configure a standalone version of logBox for logging

    Parameters:
    configPath

    containsInstance

    public boolean containsInstance(any name)

    Checks if this injector can locate a model instance or not

    Specified by:
    containsInstance in interface IInjector
    Parameters:
    name - The object name or alias to search for if this container can locate it or has knowledge of it

    doScopeRegistration

    private Injector doScopeRegistration()

    Register this injector on a user specified scope


    getBinder

    public string getBinder()


    getCacheBox

    public string getCacheBox()


    getColdbox

    public string getColdbox()


    getEventManager

    public string getEventManager()


    getEventStates

    public string getEventStates()


    getInjectorID

    public string getInjectorID()


    getInstance

    public any getInstance([any name], [any dsl], [struct initArguments='[runtime expression]'], [any targetObject=''])

    Locates, Creates, Injects and Configures an object model instance

    Specified by:
    getInstance in interface IInjector
    Parameters:
    name - The mapping name or CFC instance path to try to build up
    dsl - The dsl string to use to retrieve the instance model object, mutually exclusive with 'name
    initArguments - The constructor structure of arguments to passthrough when initializing the instance
    targetObject - The object requesting the dependency, usually only used by DSL lookups

    getJavaSystem

    public string getJavaSystem()


    getLog

    public string getLog()


    getLogBox

    public string getLogBox()


    getObjectPopulator

    public any<BeanPopulator> getObjectPopulator()

    Get an object populator useful for populating objects from JSON,XML, etc.


    getParent

    public any<Injector> getParent()

    Get a reference to the parent injector instance, else an empty simple string meaning nothing is set

    Specified by:
    getParent in interface IInjector

    getScope

    public any getScope(any scope)

    Get a registered scope in this injector by name

    Parameters:
    scope - The scope name

    getScopeRegistration

    public struct getScopeRegistration()

    Get the structure of scope registration information


    getScopes

    public string getScopes()


    getScopeStorage

    public string getScopeStorage()


    getUtil

    public any<Util> getUtil()

    Return the core util object


    getUtility

    public string getUtility()


    getVersion

    public string getVersion()


    injectTarget

    private Injector injectTarget(any target, any propertyName, any propertyObject, any scope, any argName)

    Inject a model object with dependencies via setters or property injections

    Parameters:
    target - The target that will be injected with dependencies
    propertyName - The name of the property to inject
    propertyObject - The object to inject
    scope - The scope to inject a property into, if any else empty means it is a setter call
    argName - The name of the argument to send if setter injection

    isCacheBoxLinked

    public boolean isCacheBoxLinked()

    Checks if CacheBox is linked


    isColdBoxLinked

    public boolean isColdBoxLinked()

    Checks if Coldbox application context is linked


    locateInstance

    public any locateInstance(any name)

    Tries to locate a specific instance by scanning all scan locations and returning the instantiation path. If model not found then the returned instantiation path will be empty

    Parameters:
    name - The model instance name to locate

    locateScopedSelf

    public any<Injector> locateScopedSelf()

    Return a self reference using the scoped registration, mostly used by providers or scope widening objects


    processAfterCompleteDI

    private Injector processAfterCompleteDI(any targetObject, any DICompleteMethods)

    Process after DI completion routines

    Parameters:
    targetObject - The target object to do some goodness on
    DICompleteMethods - The array of DI completion methods to call

    processInjection

    private Injector processInjection(any targetObject, any DIData, any targetID)

    Process property and setter injection

    Parameters:
    targetObject
    DIData - The DI data to use
    targetID - The target ID to process injections

    processMixins

    private Injector processMixins(any targetObject, any mapping)

    Process mixins on the selected target

    Parameters:
    targetObject - The target object to do some goodness on
    mapping - The target mapping

    processProviderMethods

    private Injector processProviderMethods(any targetObject, any mapping)

    Process provider methods on the selected target

    Parameters:
    targetObject - The target object to do some goodness on
    mapping - The target mapping

    registerDSL

    public Injector registerDSL(any namespace, any path)

    A direct way of registering custom DSL namespaces

    Parameters:
    namespace - The namespace you would like to register
    path - The instantiation path to the CFC that implements this scope, it must have an init() method and implement: coldbox.system.ioc.dsl.IDSLBuilder

    registerListener

    public Injector registerListener(any listener)

    Register all the configured listeners in the configuration file

    Parameters:
    listener - The listener to register

    registerListeners

    private Injector registerListeners()

    Register all the configured listeners in the configuration file


    registerNewInstance

    public any registerNewInstance(any name, any instancePath)

    Register a new requested mapping object instance thread safely and returns the mapping configured for this instance

    Parameters:
    name - The name of the mapping to register
    instancePath - The path of the mapping to register

    registerScopes

    private Injector registerScopes()

    Register all internal and configured WireBox Scopes


    removeFromScope

    public Injector removeFromScope()

    Remove the Injector from scope registration if enabled, else does nothing


    setBinder

    public any setBinder(any binder)

    Parameters:
    binder

    setCacheBox

    public any setCacheBox(any cacheBox)

    Parameters:
    cacheBox

    setColdbox

    public any setColdbox(any coldbox)

    Parameters:
    coldbox

    setEventManager

    public any setEventManager(any eventManager)

    Parameters:
    eventManager

    setEventStates

    public any setEventStates(array eventStates)

    Parameters:
    eventStates

    setInjectorID

    public any setInjectorID(any injectorID)

    Parameters:
    injectorID

    setJavaSystem

    public any setJavaSystem(any javaSystem)

    Parameters:
    javaSystem

    setLog

    public any setLog(any log)

    Parameters:
    log

    setLogBox

    public any setLogBox(any logBox)

    Parameters:
    logBox

    setParent

    public any setParent(any<Injector> injector)

    Link a parent Injector with this injector

    Specified by:
    setParent in interface IInjector
    Parameters:
    injector - A WireBox Injector to assign as a parent to this Injector
    Returns:
    Injector

    setScopes

    public any setScopes(any scopes)

    Parameters:
    scopes

    setScopeStorage

    public any setScopeStorage(any scopeStorage)

    Parameters:
    scopeStorage

    setUtility

    public any setUtility(any utility)

    Parameters:
    utility

    setVersion

    public any setVersion(any version)

    Parameters:
    version

    shutdown

    public any shutdown()

    Shutdown the injector gracefully by calling the shutdown events internally.

    Specified by:
    shutdown in interface IInjector