FORGEBOX Enterprise 🚀 - Take your ColdFusion (CFML) Development to Modern Times! Learn More...

Reactor factory with autowire support

v1.1 Public
This is a custom Reactor Factory object that will automatically autowire objects created by the factory. This way you can use Reactor and also take advantage of ColdBox's dependency injection.

This factory will autowire any objects created with the following factory methods:
  • createDao()
  • createDictionary()
  • createGateway()
  • createMetadata()
  • createRecord()
  • createTo()
  • createValidator()

Dependencies (0)

Dev Dependencies (0)

  1. Save ReactorFactory.cfc somewhere inside your app (ex. /model/reactor/ReactorFactory.cfc)
  2. This component extends the original ReactorFactory object, so modify the extends attribute if Reactor isn't installed in the default location (reactor.reactorFactory).
  3. Tell the ReactorLoader interceptor to use this custom factory by specifying the ReactorFactoryClassPath property in your ColdBox configuration settings. For example:
// Reactor ORM
{ class="coldbox.system.orm.reactor.ReactorLoader",
properties = {
ReactorFactoryClassPath = "#appMapping#/model/reactor/reactorFactory",
dsnAlias = "myDSN",
pathToConfigXML = "config/Reactor.xml.cfm",
project = "myProject",
mapping = "/#appMapping#/model/reactor",
mode = "production"
It's also necessary to make a few changes to your onAppInit() ColdBox event:
  1. Add autowire="true" to the <cfcomponent> tag of the event handler containing your onAppInit() method (usually Main.cfc)
  2. Add the following code after the opening <cfcomponent> line:
    <cfproperty name="reactor" inject="ocm" scope="instance" />
    <cfset Instance = StructNew() />
  3. Add the following line at the top of your onAppInit() event method code:
That's it! Now you can add autowire="true" to your Reactor objects and they will be automatically injected upon creation. Here is an example Reactor record that's injected with a ColdBox config custom setting:

<cfcomponent hint="I am the database agnostic custom Record object for the user object.  I am generated, but not overwritten if I exist.  You are safe to edit me."
    extends="reactor.project.myproject.Record.userRecord" autowire="true">
    <!--- Place custom code here, it will not be overwritten --->

    <!--- Autowire dependencies --->
    <cfproperty name="adminEmail" inject="coldbox:setting:adminEmail" scope="instance" />
    <cfset Instance = StructNew() />

    <!--- Get display authorization array or specific value from array index --->
    <cffunction name="getUsername" access="public" hint="I get the 'username' value." output="false" returntype="any" _returntype="string">
        <!--- This function now has access to the adminEmail setting from the ColdBox config --->

        <cfset Instance.adminEmail />

Inside an event handler you can then use the object just like you would any other Reactor object. Any calls to reactor.createRecord("user") will return a user record automatically injected with the specified properties.

  • Minor performance enhancement to only autowire objects with autowire=true somewhere in object's inheritance chain.
  • Original release.

$ box install Reactor-factory-with-autowire-support

No collaborators yet.
  • {{ getFullDate("Mar 30 2011 06:03 PM GMT") }}
  • {{ getFullDate("Jun 10 2016 09:06 AM GMT") }}
  • 3,816
  • 2,558
  • 1