variables
scope. This is a huge performance benefit since event handlers are wired with all necessary dependencies upon creation instead of requesting dependencies (usage) at runtime. We encourage you to use injection whenever possible.property
injection, which is the concept of defining properties in the component with a special annotation called inject
, which tells WireBox what reference to retrieve via the WireBox Injection DSL. Let's say we have a users handler that needs to talk to a model called UserService. Here is the directory layout so we can see the conventionscfproperty
with a name and inject
attribute. The name
becomes the name of the variable in the variables
scope and the inject
annotation tells WireBox what to retrieve. By default it retrieves model objects by name and path.config/WireBox.cfc
getInstance()
, which in turn delegates to WireBox's getInstance()
method. We would recommend requesting objects if they are transient (have state) objects or stored in some other volatile storage scope (session, request, application, cache, etc). Retrieving of objects is okay, but if you will be dealing with mostly singleton objects or objects that are created only once, you will gain much more performance by using injection.FunkyService.cfc
and by convention we will place it in our applications models
folder.inject
attribute. ColdBox will look for that model object by the given name in the models
folder, create it, persist it, wire it, and return it. If you execute it, you will get something like this:inject
annotation in several ways. Below is our recommendation.getInstance()
does a wirebox.getInstance()
callback (Uncle Bob), but it is a facade method that is easier to remember. If you run this, you will also see that it works and everything is fine and dandy. However, the biggest difference between injection and usage can be seen with some practical math: