Due the possibility of a contract work on a project that uses Mach-ii, Reactor and ColdSpring combo next year – I have dedicated some portion of my holiday time to get my hands dirty on these frameworks. It has been around 10 days building a simple application with the frameworks and below is my experience so far.
Getting up and running with Mach-ii (1.6) itself was relatively easy, perhaps this is due to the fact that I have played around with ColdBox and Model-Glue before. However I did have a difficult time to find out how to do some particular things in Mach-ii. To be honest, I did not sit down and go through the docs page by page – given my limited time, I just really want to get an overall picture on how things work and get a sample app up and running quickly. Also given that I have worked with ColdBox quite a lot – I sort of have a bias towards ColdBox way of doing things and documenting.
There were two particular things that I was struggling with, the 1st one was how to do layout in Mach-ii. I spent quite a bit of time going skim through documentation and doing some Googling. It turned out that it is actually there in the documentation first page. Layout was listed down on the bottom of the documentation under Common Architectural Approaches – I missed it the first time when I looked at the page because I was concentrating on Mach-ii Concepts and Introductions section (I assume that Layout must be part of Concepts section).
The other question that I have was how to reload the framework. I came few occasion where my modifications on some CFCs didn’t do anything to the application – so I suspected caching was in play. I was expecting a magic reload URL parameter like ColdBox’s fwreinit – so far I couldn’t find such a thing. Doing some Googling around found out about mach-ii dashboard that will help me in this area. So I downloaded it – dropped it in on my application and now I can reload the framework whenever I made changes to my CFC.
Other than those two issues – everything else seem to work fine. I am a bit worry with mach-ii.xml, I suspect it can get very big and messy quickly if you have a big application.
Next up was to get Reactor to work with Mach-ii. It is a straight forward affair except that somehow I have an old version of Reactor on my computer, I must’ve downloaded it ages ago and never used it. And so I got a weird error message, which unfortunately I forgot to record. After getting the latest version of Reactor – everything works as expected. Again, I have some experience with Reactor before so this part didn’t take too long.
The only part from the framework trinity that I haven’t really work with before is ColdSpring. This is probably the most difficult and time consuming part from the whole experience. Just like my issue with Reactor, I also had an older version of ColdSpring on my computer – so I faced roadblock from early on.
My biggest frustration was to get Mach-ii listener to get dependency injected by ColdSpring (setting the resolveMachIIDependencies to true in mach-ii ColdSpring configuration file) and to get mach-ii autowiring going (setting the autowireAttributeName to true in the config file) – it looks the tightest integration between Mach-ii and ColdSpring happens when those two attributes are set to true.
In order to go ahead with my learning – I decided to put on hold on this issue and resorted to:
- For first issue – manually code the dependency on the Listeners.
- For second issue – use ColdSpring autowire byName. The only problem with this approach is, I have to manually supply getters and setters for the dependencies – not much of a problem for me since this is a small application.
So finally 10 days (around 15 hours) later – I have a simple sample application running using mach-ii for MVC, running Reactor to handle the database and objects side of things and then a very basic use of ColdSpring for managing object dependencies.
On reflection, getting the three frameworks to work together is actually not too hard conceptually – but the hardest part for me was getting the right information on the configuration, especially for ColdSpring – so I will post my ColdSpring and Mach-ii config files on my next blog post.


Auto-wiring dependencies in the listener is very easy with Mach-II. Simply add a “depends” attribute into the component declaration:
This attribute is “depends” by default, but can be changed according to the value of the autowireAttributeName property of the ColdSpring property object as declared in your configuration file.
In regards to the configuration file becoming very large, it is possible to build it out with includes or separating your application into modules and configuring them individually. See the Mach-ii docs for info on these options.
Regarding reloading the framework, one common approach is to add some additional logic to Application.cfc (if it isn’t there already). In the OnRequestStart method, do something like this:
(code got hidden, trying again)…
Auto-wiring dependencies in the listener is very easy with Mach-II. Simply add a “depends” attribute into the component declaration:
<cfcomponent output=”false” hint=”someListener” extends=”MachII.framework.Listener” depends=”someService”>
This attribute is “depends” by default, but can be changed according to the value of the autowireAttributeName property of the ColdSpring property object as declared in your configuration file.
In regards to the configuration file becoming very large, it is possible to build it out with includes or separating your application into modules and configuring them individually. See the Mach-ii docs for info on these options.
Regarding reloading the framework, one common approach is to add some additional logic to Application.cfc (if it isn’t there already). In the OnRequestStart method, do something like this:
<cfif StructKeyExists(url, “reinitApp”)>
<cfsetting requesttimeout=”120″ />
<cfset MACHII_CONFIG_MODE = 1 />
</cfif>
Hi Joel,
Thanks for the tips. I did try the depends attribute by setting autowireAttributeName to true, but I got an error immediately – I couldn’t resolved the error. Maybe I’ll ask people in mach-ii in the mailing list.
Did you add the ColdSpring property cfc to your Mach-ii properties declarations in the configuration file?
<property name=”coldSpringProperty” type=”MachII.properties.ColdspringProperty”>
<parameters>
<parameter name=”beanFactoryPropertyName” value=”serviceFactory”/>
<parameter name=”configFile” value=”config/services.xml”/>
<parameter name=”configFilePathIsRelative” value=”true”/>
<parameter name=”resolveMachIIDependencies” value=”true”/>
<parameter name=”placeFactoryInApplicationScope” value=”true”/>
<parameter name=”autowireAttributeName” value=”depends”/>
</parameters>
</property>
Thank you for documenting your experiences. We on the Mach II are always looking for feedback and help on improving our documentation for new users. We also have a very helpful mailing list that can usually pretty quickly help with questions.
We do have a pre-build Mach II app skeleton that has a ColdSpring integrated option in it which might have helped for some of your setup issues. Also we have document right in the ColdSpringProperty cfc which explains how to set it up in addition to the documentation on the wiki and in the skeleton app. Do you check out the skeleton app by any chance?
@Joel, yes I think so, there is an include to the mach-ii_coldspringProperty.xml from mach-ii.xml and this set up works for me:
<property name="coldspringProperty" type="MachII.properties.ColdspringProperty">
<parameters>
<parameter name="beanFactoryPropertyName" value="serviceFactory"/>
<parameter name="configFile" value="config/coldspring.xml"/>
<parameter name="configFilePathIsRelative" value="true"/>
<!– Flag to indicate whether to resolve dependencies for listeners/filters/plugins Default: FALSE –>
<parameter name="resolveMachIIDependencies" value="false"/>
<parameter name="parentBeanFactoryScope" value="application"/>
<parameter name="parentBeanFactoryKey" value="false"/>
<parameter name="placeFactoryInApplicationScope" value="true" />
<parameter name="placeFactoryInServerScope" value="false" />
<parameter name="autowireAttributeName" value="depends" />
</parameters>
</property>
My problem is eventhough I set the autowireAttributeName to depends on the setting and then on my service CFC I put the depends keyword on the component declaration, but I couldn’t get the autowiring to work. So I had to resort using the usual ColdSpring byName autowiring.
@Kurt, thanks for your kind words. I did use the skeleton to build the sample app. You are right, perhaps I wasn’t reading the comments on the coldspringProperty.xml thoroughly.
Felix, check out the ColdSpringProperty documentation on the wiki:
http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/UsingColdSpringWithMach-II
The reason why the “depends” attribute isn’t working for you is because it’s part of Mach-II Simplicity – 1.8 (which is will be going into RC2 soon). I’d recommend just upgrading to that version so you can all the new goodies including the depends attribute.
Hi Peter,
Ah alright that makes sense. Thanks.