Loading...
Loading...
Loading...
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 interacts with the loaded LogBox instance.
Injects providers of objects, meaning a proxy object that knows how to retrieve and construct the desired target object. This is a great way to delay construction or deal with non-singleton objects without causing memory leaks.
This DSL namespace is only active if using CacheBox or a ColdBox application context.
In order to use this namespace you will need the cborm
module installed in your application: install cborm
Gives you the ability to easily inject base ORM services or binded virtual entity services for you:
The executor namespace is both available in ColdBox and WireBox standalone and it is used to get references to created asynchronous executor thread pools.
You can also request Java objects from the injection dsl.
DSL
Description
coldbox
Get the ColdBox controller reference
DSL
Description
coldbox:appScheduler
Get a reference to the global application scheduler
coldbox:asyncManager
Get a reference to the ColdBox Async Manager
coldbox:configSettings
Get the application's configuration structure
coldbox:coldboxSettings
Get the framework's configuration structure
coldbox:dataMarshaller
Get the ColdBox data marshaling reference
coldbox:flash
Get a reference to the application's flash scope object
coldbox:handlerService
Get a reference to the handler service
coldbox:interceptorService
Get a reference to the interceptor service
coldbox:loaderService
Get a reference to the loader service
coldbox:moduleService
Get a reference to the ColdBox Module Service
coldbox:moduleConfig
Get a reference to the entire modules
configuration struct
coldbox:renderer
Get the ColdBox rendering engine reference
coldbox:requestService
Get a reference to the request service
coldbox:requestContext
Get a reference to the current request context object in the request.
coldbox:router
Get a reference to the application global router.cfc
coldbox:routingService
Get a reference to the Routing Service
coldbox:schedulerService
Get a reference to the Scheduler Service
DSL
Description
coldbox:interceptor:{name}
coldbox:moduleSettings:{module}
Inject the entire {module} settings structure
coldbox:moduleConfig:{module}
Inject the entire {module} configurations structure
coldbox:coldboxSetting:{setting}
Get a ColdBox setting {setting} and inject it
coldbox:setting:{setting}
Get the ColdBox application {setting} setting and inject it
coldbox:setting:{setting}@{module}
Get the ColdBox application {setting} from the {module} and inject it
DSL
Description
coldbox:moduleSettings:{module}:{setting}
Get a module setting. Very similar to the 3rd level dsl
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
DSL
Description
provider
Build an object provider that will return the mapping according to the property, method or argument name.
provider:{name}
Build an object provider that will return the {name}
mapping.
provider:{injectionDSL}
Build an object provider that will return the object that the {injectionDSL
} refers to
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
wirebox
Get a reference to the current injector
DSL
Description
wirebox:asyncManager
Get a reference to the Async Manager
wirebox:binder
Get a reference to the injector's binder
wirebox:eventManager
Get a reference to injector's event manager
wirebox:parent
Get a reference to the parent injector (if any)
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:populator
Get a reference to a WireBox's Object Populator utility
DSL
Description
wirebox:property:{name}
Retrieve one key of the properties structure
wirebox:scope:{scope}
Get a direct reference to an internal or custom scope object
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 |
| Inject an executor using the property name as the key |
| Inject an executor by name |
DSL | Description |
| Get a reference to the passed in |
DSL | Description |
| Same as saying id. Get a mapped instance with the same name as defined in the property, argument or setter method. |
| Get a mapped instance with the same name as defined in the property, argument or setter method. |
| Get a mapped instance with the same name as defined in the property, argument or setter method. |
| Description |
| Get a mapped instance by using the second part of the DSL as the mapping name. |
| Get a mapped instance by using the second part of the DSL as the mapping name. |
| Description |
| Get the {name} instance object, call the {method} and inject the results |
| Get the {name} instance object, call the {method} and inject the results |