WireBox allows you to create your own object persistence scopes so you can have full control on their lifecycle. This is easily done in the following process:
Create a CFC that implements wirebox.system.ioc.scopes.IScope
Register your custom scope in your configuration binder
You can create your own persistence scope or if you are getting funky, override the internal persistence scopes with your own logic.
The scope interface can be found here: coldbox.system.ioc.scopes.IScope
.
Please note that you DO NOT need to add the implements
to your code. We actually highly suggest you don't. There are many issues with interfaces yet in multiple CFML engines. So we do runtime checks for it, instead at compile time.
Now I can use the ortus
scope in my mappings DSL and even my annotations, isn't that cool!
The scoping process must be done by using some of the referenced injector's methods:
buildInstance(mapping, initArguments)
autowire()
These methods must be called sequentially in order to avoid circular reference locks. The first method buildInstance
is used to construct and initialize an object instance. The autowire method is used then to process DI and AOP on the targeted object. Let's look at the RequestScope
object:
Caution Always make sure that you use the
buildInstance
method and then store the results in the scope before wiring is done to avoid endless loops errors.