ColdBox and ColdSpring Hard Lessons

It has been a few weeks now of me getting to grips with ColdBox and ColdSpring. My question has been mainly on why I would use ColdSpring at all. Some will be glad to hear I am starting to see how ColdSpring helps with managing CFC's. I also just wanted to recommend Jason Dean's Blog. He has provided a very insightful step by step guide to using ColdBox and ColdSpring which has really helped me. I got it late, I know but if for some strange reason you have not read his series, do it, do it now!

The Hard Lesson

When I was creating my object i.e "userservice().init()" CF was throwing an error. It seemed ColdSpring knew nothing about my injected properties to the CFC, can you spot why? Well either ColdSpring or ColdBox (not sure which) handles the .init() it calls the constructor and passes in the correct argument without my help. So because I was trying to call the init() myself it was not being managed by ColdSpring. Simple, but it held me up for a long time. Because I always try and follow the best practice it never occurred to me this could be the culprit. A quick post on the ColdSpring user group and Brian Kotek quickly put me on the right track, thanks again.

DNS, DNS, where are you?

All the examples I found online show injecting the DNS setting into a userGateway using a property in the actual coldspring.xml config file. However my DNS setting are already in my coldbox config file so why repeat it again! No need! Coldbox has made it easy to create a bean and inject that too, cool!

   view plainprintabout
 <beans default-autowire="byName"><!--Autowire by name-->
 <bean id="coldboxFactory" class="coldbox.system.extras.ColdboxFactory" />
 <!--Create Config Bean-->
 <bean id="ConfigBean" factory-bean="ColdboxFactory" factory-method="getConfigBean" />
 <!--Create DNS Bean-->    
 <bean id="dsnBean" factory-bean="ColdboxFactory" factory-method="getDatasource">
     <constructor-arg name="alias">
     <value>DBDetails</value>
     </constructor-arg>
10  </bean>    
11   <bean id="adminUsersGateway" class="salesMaxx.model.adminUsersGateway">
12   <!--Gateway Bean needs DNS to be injected from DNS Bean!-->
13   <constructor-arg name="dsnBean">
14   <ref bean="dsnBean" />
15   </constructor-arg>
16   </bean>
17   <bean id="adminUsersService" class="salesMaxx.model.adminUsersService">
18   <property name="adminUsersGateway">
19   <ref bean="adminUsersGateway" />
20   </property>
21   </bean>
22  </beans>

Things I have found awesome (so far)

Finding out I no longer need to create an object! Yes ColdBox has an Autowire Interceptor for allowing you to set up dependency injection for handlers, plugins and interceptors, thats simple but cool!

To be continue when I get more time to play!

TweetBacks
Comments
 

About Me

Glyn Jackson, 27 years old, MD and senior developer of a development firm based in Staffordshire called Newebia Ltd. Academic background in BSc Information System & Internet Commerce. Online marketing expert (EE Ranked) and .NET developer. Has been developing with ColdFusion for 5 years and loves it. "I am not a veteran in ColdFusion but I do work on challenging projects which help me learn more about ColdFusion and if I can contribute to the community in anyway then, it's all good!"

Recommends

  • ColdFusion