WireBox allows you to create your own DSL object builders and then register them via your configuration binder. This allows you to create a namespace or override an internal namespace with your own object builder. By now we have seen our injection DSL and noticed that we have internal namespaces. With this feature we can alter it or create new ones so our annotations and injection DSLs can be customized to satisfaction. This is easily done in the following process
Create a CFC that implements wirebox.system.ioc.dsl.IDSLBuilder
Register your custom DSL builder in your configuration binder
To register a custom namespace in WireBox, place the following configuration in the wirebox
struct defined within the configure()
method of your WireBox binder CFC. in a ColdBox app, this is /config/WireBox.cfc
. Alternatively, you can use the mapDSL()
call in the configure()
method.
If you want to register a custom DSL namespace from a module, you can make the same call via the binder
reference that is provided to your ModuleConfig.cfc
.
Now I can use the ortus
DSL Namespace in my mappings DSL and even my annotations, isn't that cool!
Injectors allow you to register custom DSLs at runtime by using the registerDSL()
method on any injector.
This will register a new injection DSL namespace called ortus that maps to that instantiation component path.model.dsl.OrtusBuilder
. Here is a very simple DSL Builder:
As you can see from the sample, creating your own DSL builder is fairly easy. The benefits of a custom DSL builder is that you can very easily create and extend the injection DSL language to your own benefit and if you are funky enough, override the behavior of the internal DSL Namespaces.