Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Before we start building our objects, we need to understand how WireBox injects dependencies for us. You can define injections using the configuration inside the binder (like any other DI framework), but the easiest approach is to use our injection annotation and conventions (called the injection DSL). The injection DSL can be applied to cfproperty
, cfargument
, cffunction
or called via getInstance()
as we saw previously.
You can utilize the injection DSL by adding an attribute called inject
to properties, arguments and functions. This attribute is like your code shouting, "Hey, I need something here. Hello! I need something!" That something might be another object, setting, cache, etc. The value of the inject
attribute is a string that represents the concept of retrieving an object mapped in WireBox. It can be an object path, an object ID, a setting, a datasource, custom data, etc.
Info: If you don't like annotations or find them obtrusive, you don't have to use them :). Just leverage the WireBox binder to define dependencies instead.
Here are a few examples showing how to apply the injection DSL.
Property Annotation
Constructor Argument Annotation
Setter Method Annotation
You can learn more about the supported injection DSLs in the WireBox Injection DSL documentation.
This DSL namespace is only active if using CacheBox or a ColdBox application context.
This injection namespace comes from the cborm
module extensions (https://github.com/ColdBox/cbox-cborm). It gives you the ability to easily inject base ORM services or binded virtual entity services for you:
Talk and get objects from the current wirebox injector
This namespace is a combination of namespaces that are only active when used within a ColdBox application:
The default namespace is not specifying one. This namespace is used to retreive either named mappings or full component paths.
This DSL namespace interacts with the loaded LogBox instance.
DSL
Description
cachebox
Get a reference to the application's CacheBox instance
cachebox:{name}
Get a reference to a named cache inside of CacheBox
cachebox:{name}:{objectKey}
Get an object from the named cache inside of CacheBox according to the objectKey
DSL
Description
entityService
Inject a BaseORMService object for usage as a generic service layer
entityService:{entity}
Inject a VirtualEntityService object for usage as a service layer based off the name of the entity passed in.
DSL
Description
wirebox
Get a reference to the current injector
wirebox:parent
Get a reference to the parent injector (if any)
wirebox:eventManager
Get a reference to injector's event manager
wirebox:binder
Get a reference to the injector's binder
wirebox:populator
Get a reference to a WireBox's Object Populator utility
wirebox:scope:{scope}
Get a direct reference to an internal or custom scope object
wirebox:properties
Get the entire properties structure the injector is initialized with. If running within a ColdBox context then it is the structure of application settings
wirebox:property:{name}
Retrieve one key of the properties structure
DSL
Description
coldbox
Get the coldbox controller reference
coldbox:flash
Get a reference to the application's flash scope object
coldbox:setting:{setting}
Get the coldbox application {setting} setting and inject it
coldbox:fwSetting:{setting}
Get a ColdBox setting {setting} and inject it
coldbox:setting:{setting}@{module}
Get the coldbox application {setting} from the {module} and inject it
coldbox:datasource:{alias}
Get a new datasource struct according to {alias}
coldbox:loaderService
Get a reference to the loader service
coldbox:requestService
Get a reference to the request service
coldbox:handlerService
Get a reference to the handler service
coldbox:interceptorService
Get a reference to the interceptor service
coldbox:moduleService
Get a reference to the ColdBox Module Service
coldbox:renderer
Get the ColdBox rendering engine reference
coldbox:dataMarshaller
Get the ColdBox data marshalling reference
coldbox:interceptor:{name}
Get a reference of a named interceptor {name}
coldbox:configSettings
Get the application's configuration structure
coldbox:fwSettings
Get the framework's configuration structure
coldbox:fwSetting:{setting}
Get a setting from the ColdBox settings instead of the Application settings
coldbox:moduleSettings:{module}
Inject the entire {module} settings structure
coldbox:moduleConfig:{module}
Inject the entire {module} configurations structure
DSL
Description
empty
Same as saying id. Get a mapped instance with the same name as defined in the property, argument or setter method.
id
Get a mapped instance with the same name as defined in the property, argument or setter method.
id:{name}
Get a mapped instance by using the second part of the DSL as the mapping name.
id:{name}:{method}
Get the {name} instance object, call the {method} and inject the results
model
Get a mapped instance with the same name as defined in the property, argument or setter method.
model:{name}
Get a mapped instance by using the second part of the DSL as the mapping name.
model:{name}:{method}
Get the {name} instance object, call the {method} and inject the results
DSL
Description
logbox
Get a reference to the application's LogBox instance
logbox:root
Get a reference to the root logger
logbox:logger:{category name}
Get a reference to a named logger by its category name
logbox:logger:{this}
Get a reference to a named logger using the current target object's path as the category name