variablesscope. 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.
propertyinjection, 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 conventions
cfpropertywith a name and
namebecomes the name of the variable in the
variablesscope and the
injectannotation tells WireBox what to retrieve. By default it retrieves model objects by name and path.
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.cfcand by convention we will place it in our applications
injectattribute. ColdBox will look for that model object by the given name in the
modelsfolder, create it, persist it, wire it, and return it. If you execute it, you will get something like this:
injectannotation in several ways. Below is our recommendation.
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: