lucee.Component
wirebox.system.ioc.Injector
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. All injectors implement: wirebox.system.ioc.IInjector Easy Startup:
injector = new wirebox.system.ioc.Injector();Inline Config:
injector = new wirebox.system.ioc.Injector( { scopeRegistration : { enabled : false } } );
Binder Startup
injector = new wirebox.system.ioc.Injector(new MyBinder());Binder Path Startup
injector = new wirebox.system.ioc.Injector( "config.MyBinder" );
| Property Summary | ||||
|---|---|---|---|---|
| type | property | default | serializable | required |
any
|
asyncManager
The Global AsyncManager.
|
true
|
false
|
|
any
|
binder
The Configuration Binder object.
|
true
|
false
|
|
any
|
cacheBox
CacheBox Link.
|
true
|
false
|
|
struct
|
childInjectors
An injector can have children injectors referenced by a unique name.
|
true
|
false
|
|
any
|
coldbox
ColdBox Application Link.
|
true
|
false
|
|
any
|
eventManager
Event Manager Link.
|
true
|
false
|
|
array
|
eventStates
Configured Event States.
|
true
|
false
|
|
any
|
injectorID
The injector Unique ID.
|
true
|
false
|
|
any
|
log
Log Reference.
|
true
|
false
|
|
any
|
logBox
LogBox and Class Logger.
|
true
|
false
|
|
string
|
name
The name of the injector.
|
true
|
false
|
|
any
|
objectBuilder
The object builder for this injector.
|
true
|
false
|
|
any
|
parent
Parent Injector.
|
true
|
false
|
|
any
|
root
Root Injector instance.
|
true
|
false
|
|
any
|
scopeStorage
Scope Storages Utility.
|
true
|
false
|
|
any
|
scopes
LifeCycle Scopes.
|
true
|
false
|
|
any
|
taskScheduler
The logBox task scheduler executor.
|
true
|
false
|
|
any
|
utility
ColdBox Utility class.
|
true
|
false
|
|
any
|
version
WireBox Version.
|
true
|
false
|
|
| Constructor Summary | |
|---|---|
|
init([any binder='wirebox.system.ioc.config.DefaultBinder'], [struct properties='[runtime expression]'], [any<wirebox.system.web.Controller> coldbox=''], [any name='root'])
WireBox can be constructed with no parameters and it will use the default binder: `wirebox. |
|
| 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, 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([any scopeInfo='[runtime expression]'])
Register this injector on a user specified scope. |
string
|
getAsyncManager()
|
string
|
getBinder()
|
string
|
getCacheBox()
|
Injector
|
getChildInjector(any name)
Get a child injector from this injector. |
array
|
getChildInjectorNames()
Get an array of all the registered child injectors in this injector. |
string
|
getChildInjectors()
|
string
|
getColdbox()
|
string
|
getEventManager()
|
string
|
getEventStates()
|
string
|
getInjectorID()
|
Injector
|
getInjectorReference(any name)
Get an injector reference by unique name. |
array
|
getInjectorReferenceNames()
Get an array of registered injector references. |
any
|
getInstance([any name], [struct initArguments='[runtime expression]'], [any dsl], [any targetObject=''], [any injector])
Locates, Creates, Injects and Configures an object model instance. |
string
|
getLog()
|
string
|
getLogBox()
|
string
|
getName()
|
string
|
getObjectBuilder()
|
any
|
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. |
string
|
getRoot()
|
any
|
getScope(any scope)
Get a registered scope in this injector by name. |
struct
|
getScopeRegistration()
Get the structure of scope registration information. |
string
|
getScopeStorage()
|
string
|
getScopes()
|
string
|
getTaskScheduler()
|
string
|
getUtility()
|
string
|
getVersion()
|
boolean
|
hasChildInjector(any name)
Verify if a child injector has been registered by name. |
boolean
|
hasParent()
Has a parent injector. |
boolean
|
hasRoot()
Has a root injector. |
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 any
|
processDelegation(any target, string targetID, any delegate, any DIData)
Process a target object dependency delegation. |
private Injector
|
processInjection(any targetObject, array DIData, string targetID, any mapping)
Process property and setter injections. |
private Injector
|
processLazyProperties(any targetObject, any mapping)
Process lazy properties on the target object. |
private Injector
|
processMixins(any targetObject, any mapping)
Process mixins on the selected target. |
private Injector
|
processObservedProperties(any targetObject, any mapping)
Process observed properties on the target object. |
private Injector
|
processProviderMethods(any targetObject, any mapping)
Process provider methods on the selected target. |
Injector
|
registerChildInjector(any name, any child)
Register a child injector instance with this injector and set this injector as a parent of the child. |
Injector
|
registerDSL(any namespace, any path)
A direct way of registering custom DSL namespaces. |
Injector
|
registerInjectorReference(any injector)
Register an injector to be tracked in the lookup reference map. |
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. |
boolean
|
removeChildInjector(any name)
Remove a child injector from this injector. |
Injector
|
removeFromScope()
Remove the Injector from scope registration if enabled, else does nothing. |
any
|
setAsyncManager(any asyncManager)
|
any
|
setBinder(any binder)
|
any
|
setCacheBox(any cacheBox)
|
any
|
setChildInjectors(struct childInjectors)
|
any
|
setColdbox(any coldbox)
|
any
|
setEventManager(any eventManager)
|
any
|
setEventStates(array eventStates)
|
any
|
setInjectorID(any injectorID)
|
any
|
setLog(any log)
|
any
|
setLogBox(any logBox)
|
any
|
setName(string name)
|
any
|
setObjectBuilder(any objectBuilder)
|
any
|
setParent(any<Injector> injector)
Link a parent Injector with this injector. |
any
|
setRoot(any root)
|
any
|
setScopeStorage(any scopeStorage)
|
any
|
setScopes(any scopes)
|
any
|
setTaskScheduler(any taskScheduler)
|
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 |
|---|
WireBox can be constructed with no parameters and it will use the default binder: `wirebox.system.ioc.config.DefaultBinder` for configuration and place the instance in `application.wirebox` scope for easy access. However you can also instantiate Wirebox with: - A binder instance - A binder path - A WireBox configuration DSL structure
binder - A binder instance, path, or DSL structure to configure WireBox withproperties - A structure of binding properties to passthrough to the Binder Configuration CFCcoldbox - A coldbox application context that this instance of WireBox can be linked to, if not using it, we just ignore it.name - The internal name of the injector, defaults to 'root' if not passed| Property Detail |
|---|
The Global AsyncManager
access - publicrequired - falsereturntype - anysee - wirebox.system.async.AsyncManagerserializable - trueThe Configuration Binder object
access - publicrequired - falsereturntype - anyserializable - trueCacheBox Link
access - publicrequired - falsereturntype - anyserializable - trueAn injector can have children injectors referenced by a unique name
access - publicrequired - falsereturntype - anyserializable - trueColdBox Application Link
access - publicrequired - falsereturntype - anyserializable - trueEvent Manager Link
access - publicrequired - falsereturntype - anyserializable - trueConfigured Event States
access - publicrequired - falsereturntype - anyserializable - trueThe injector Unique ID
access - publicrequired - falsereturntype - anyserializable - trueLog Reference
access - publicrequired - falsereturntype - anyserializable - trueLogBox and Class Logger
access - publicrequired - falsereturntype - anyserializable - trueThe name of the injector
access - publicrequired - falsereturntype - anyserializable - trueThe object builder for this injector
access - publicrequired - falsereturntype - anyserializable - trueParent Injector
access - publicrequired - falsereturntype - anyserializable - trueRoot Injector instance
access - publicrequired - falsereturntype - anyserializable - trueScope Storages Utility
access - publicrequired - falsereturntype - anyserializable - trueLifeCycle Scopes
access - publicrequired - falsereturntype - anyserializable - trueThe logBox task scheduler executor
access - publicrequired - falsereturntype - anysee - wirebox.system.async.executors.ScheduledExecutorserializable - trueColdBox Utility class
access - publicrequired - falsereturntype - anyserializable - trueWireBox Version
access - publicrequired - falsereturntype - anyserializable - true| Method Detail |
|---|
I wire up target objects with dependencies either by mappings or a-la-carte autowires
target - The target object to wire upmapping - The object mapping with all the necessary wiring metadata. Usually passed by scopes and not a-la-carte autowirestargetID - 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 wiringannotationCheck - 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.Load a configuration binder object according to passed in type
binder - The data CFC configuration instance, instantiation path or programmatic binder object to configure this injector withproperties - A map of binding properties to passthrough to the Configuration CFCBuild an instance, this is called from registered scopes only as they provide locking and transactions
mapping - The mapping to constructinitArguments - The constructor structure of arguments to passthrough when initializing the instanceClear the singleton cache
Configure this injector for operation, called by the init(). You can also re-configure this injector programmatically, but it is not recommended.
binder - The configuration binder object or path or dsl structure to configure this Injector instance withproperties - A structure of binding properties to passthrough to the Configuration CFCConfigure a standalone version of cacheBox for persistence
config - The cacheBox configuration data structureConfigure a standalone version of a WireBox Event Manager
Configure a standalone version of logBox for logging
configPathChecks if this injector can locate a model instance or not
name - The object name or alias to search for if this container can locate it or has knowledge of itRegister this injector on a user specified scope
scopeInfo - The scope info struct: key, scopeGet a child injector from this injector
nameGet an array of all the registered child injectors in this injector
Get an injector reference by unique name
name - The unique injector reference nameGet an array of registered injector references
Locates, Creates, Injects and Configures an object model instance
name - The mapping name or CFC instance path to try to build upinitArguments - The constructor structure of arguments to passthrough when initializing the instancedsl - The dsl string to use to retrieve the instance model object, mutually exclusive with 'nametargetObject - The object requesting the dependency, usually only used by DSL lookupsinjector - The child injector to use when retrieving the instanceGet an object populator useful for populating objects from JSON,XML, etc.
Get a reference to the parent injector instance, else an empty simple string meaning nothing is set
Get a registered scope in this injector by name
scope - The scope nameGet the structure of scope registration information
Verify if a child injector has been registered by name
name - The name of the child injector to checkHas a parent injector
Has a root injector
Inject a model object with dependencies via setters or property injections
target - The target that will be injected with dependenciespropertyName - The name of the property to injectpropertyObject - The object to injectscope - The scope to inject a property into, if any else empty means it is a setter callargName - The name of the argument to send if setter injectionChecks if CacheBox is linked
Checks if Coldbox application context is linked
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
name - The model instance name to locateReturn a self reference using the scoped registration, mostly used by providers or scope widening objects
Process after DI completion routines
targetObject - The target object to do some goodness onDICompleteMethods - The array of DI completion methods to callProcess a target object dependency delegation
target - The target object being injected with dependencies/delegationstargetID - The target ID to process injectionsdelegate - The delegation object that was injectedDIData - The DI information about the delegation/injectionProcess property and setter injections
targetObject - The target object to do some goodness on, usually a CFCDIData - The DI data array to use for injectiontargetID - The target Identifier of the target objectmapping - The mapping of the target objectProcess lazy properties on the target object
targetObject - The target object to do some goodness onmapping - The target mappingProcess mixins on the selected target
targetObject - The target object to do some goodness onmapping - The target mappingProcess observed properties on the target object
targetObject - The target object to do some goodness onmapping - The target mappingProcess provider methods on the selected target
targetObject - The target object to do some goodness onmapping - The target mappingRegister a child injector instance with this injector and set this injector as a parent of the child.
name - The unique name to register the child withchild - The child Injector instance to registerA direct way of registering custom DSL namespaces
namespace - The namespace you would like to registerpath - The instantiation path to the CFC that implements this scope, it must have an init() method and implement: wirebox.system.ioc.dsl.IDSLBuilderRegister an injector to be tracked in the lookup reference map. Used for providers mostly.
injector - The injector to trackRegister all the configured listeners in the configuration file
listener - The listener to registerRegister all the configured listeners in the configuration file
Register a new requested mapping object instance thread safely and returns the mapping configured for this instance
name - The name of the mapping to registerinstancePath - The path of the mapping to registerRegister all internal and configured WireBox Scopes
Remove a child injector from this injector
name - The unique name of the child injector to removeRemove the Injector from scope registration if enabled, else does nothing
asyncManagerbindercacheBoxchildInjectorscoldboxeventManagereventStatesinjectorIDloglogBoxnameobjectBuilderLink a parent Injector with this injector
injector - A WireBox Injector to assign as a parent to this InjectorrootscopeStoragescopestaskSchedulerutilityversionShutdown the injector gracefully by calling the shutdown events internally.