This blog has moved to http://www.andyjarrett.co.uk/blog/ | New RSS FEED

My blog has moved

Please update your bookmarks and feeds for my site.

I now have a Mango Blog at:

http://www.andyjarrett.com/blog

Feed URL: http://feeds.feedburner.com/andyjarrett

ColdSpring and Remote Facades

ColdSpring is just indispensable when developing any size app but as a part of its Inversion of Control, or IoC it does a lot more. When developing a project with a framework I usually have a need to have remote access to my model. One of the usual methods is to still go through the framework itself. The reason is that you've got ColdSpring (in most cases) handling all the injections and its just easier to keep it one place. For me I prefer to use a single service layer component which can access the model and this is where CS fits in.

CS can create remote facades which exposes any remote methods(access="remote") you have in a component.

What I am going to explain over a couple of posts is a technique that I am looking at implement in project thats slowly being worked on

I am assuming if you've made it this far you know CS so I'm going to jump straight in. If you don't, I know a good place to start. First of the directory structure for this guide.

  • web root
    • remote_cs
      • com
        • users
      • config

In the config folder we're going to place our ColdSpring.xml configuration file which at the moment looks like this with reference to one bean:

[*** More ***]

Passing Application scoped variables to ColdSpring within Model Glue

Passing defaultProperties in ColdSpring with Model Glue

Or Using defaultProperties with CS and MG. I couldn't figure out which title would be better.

Basically this is a guide on how to pass variables into ColdSpring. In my case from the Application scope. Recently I've been working on a Model Glue, Transfer, and ColdSpring app and came across a problem which I couldn't find a direct answer to online. The application I'm working is only a small part of the site and has some settings in the Application scope which needs to remain there. Usually I put all my variables in a ColdSpring/Model Glue simpleConfig Bean (using the class ModelGlue.Bean.CommonBeans.SimpleConfig) but this time I needed CS to get the variables from the application scope. This actually isn't too hard as you can pass properties(dynamic variables) into the config.xml e.g.

Here's the code for creating the bean factory. You would find this in onApplicationStart or at the top of your Application.cfm.

Code for Application.cfm/cfc


<!-- First we create our global vars in the Application scope -->
<cfset application.settings = structNew() />
<!-- Add our DSN name to the Settings struct -->
<cfset application.settings.dsn = "myDSN" />
<!-- If our bean factory doesn't exist then we create it. You could also check for a url.reinit var as well here -->
<cfif NOT isDefined("application.beanFactory")>
    <!-- Our struct to hold the variables we are going to pass to ColdSpring -->
    <cfset properties = structNew() />
    <!-- Our struct to hold the variables we are going to pass to ColdSpring -->
    <cfset properties.dsn = "dsn_reference">
    <!-- Create our bean object -->    
    <cfset application.beanFactory = createObject("component","coldspring.beans.DefaultXmlBeanFactory").init(structNew(), properties)/>
    <!-- Pass a fully qualified path to a bean definition xml file -->
    <cfset application.beanFactory.loadBeansFromXmlFile(expandPath('/config/beans.xml'), true)/>
</cfif>

In our Beans.xml we need to reference the properties structure by the key.

[*** More ***]

Frameworks DTD files

I hope this doesn't come across as a moan as its meant to be more of a general question to the community. But with all the main frameworks out there running on XML config files, where are the official DTD's hosted for these? I know there are several around hosted in odd locations (no disrespect), but I was just looking to put together a definitive list of the locations.

I know you can get them via subversion etc but shouldn't/couldn't they be hosted on the respective sites??

The Rough Guides

In case no one has noticed I am kind of starting a Rough Guide Series. These guides are made the way I like guides to be. They don't go in-depth and throw everything at you! They just do enough to get you up and walking and give you an understanding of the topic. For example the ColdSpring series were done with this in mind. I just wanted to help get the idea to finally click and see what it is good for. They seemed to of done well from looking at the views and they even got a mention in the CFWeekly(cheers guys, keep up the good work!). Along with this I will also offer links/resources to carry on where I leave off.

What will I be covering next.

[*** More ***]

Multi-lingual site with Model-Glue and Coldspring

Now and then through my work I get asked to create a site with multi-lingual support. In the past I have usually just created a custom tag or UDF. This time, now that I am on A href="http://model-glue.com/">Model Glue: Unity I wanted something that was a little more integrated so I decided to use Ray Camden modified ResourceBundle.cfc. This cfc was actually created by Paul Hastings and you can find more information here.

There are two reasons I am posting this mini guide, first to share and the second is that knowing me I am probably doing something inefficient and by letting the community see it hopefully someone will point out any errors or an easier way to do things :o)

[*** More ***]

Passing Properties to ColdSpring

Dan Vega has recently posted on his blog a small tutorial of how to pass properties to ColdSpring. Well worth a look to understand more benefits that dependecy injections brings to the table.

ColdSpring and Dependency Injection for the beginner part 3: Setter Injection.

Onto part 3 of this rough beginners tutorial. By now you should of read part 1 and part 2 and this is the final part of me explaining Dependency Injection. This doesn't mean that come the end of this post you'll now know everything. But you'll know the basics, and be able to walk away and understand a little more of how and where to use ColdSpring.

To go back a little as since my first post there has been for my American readers a national holiday - Deep Fried Turkey day or Thanksgiving as it is better known (sorry I had to mention the deep fried [whole]turkey, I don't know if it because I'm British, but it just seems wrong!). Back to the code.....todays topic is is Setter Injection and to recap from the ColdSpring site;

<property name="propertyName" />
Similar in nature to constructor arg, however in this case ColdSpring will pass some value or object reference into your bean as an argument to a setter method, identified via the name attribute. Thus, your CFC must have a setter method name that matches the property tag's name attribute (for example if your property is named "foo" then your CFC needs a setFoo() method).

[*** More ***]

ColdSpring and Dependency Injection for the beginner part 2: Constructor Injection.

Time to code! woohoo! I am going to carry on with the components from the last post which are userService and userDAO in a "model" directory on the root. For this post we'll assume that my DAO only has basic CRUD methods; Create, Read, Update, and Delete

I am going to demonstrate the Constructor Injection method of dependency injection which was summarised quickly in my last post. I think a recap is need here:

<constructor-arg name="argumentName"/>
This tag will cause Coldspring to supply your bean with a value or object reference when it is instantiated (during a CFC's init() method), passed as an argument named via the name attribute.

What the above statement means in basic terms is that the userService must have an init() method which accepts the userDAO object as an argument and sets it to a variable. e.g.

[*** More ***]

ColdSpring and Dependency Injection for the beginner part 1

First off let me caveat this post by saying that I am no an OO guru, if you are looking for a more indepth look at DI, IOC, Constructors, setters/getter etc then you should really check out sites like Peter Bells site, Application Generation.

Ok, I am going to make this first post small (I know, I know boring chat first code later) and just give a little background in preparation for the next part which will be the code (I promise). This post also isn't for the total beginner to Coldspring. Really at this point you should know why you want to use Dependency Injections(DI) and roughly understand or know the benefits when it comes to a ColdSpring.xml file. If you are looking for an introduction to ColdSpring go to the docs section of the CS site, honestly they are really good and the introduction explains a lot.

So, you should know that ColdSpring is an inversion-of-control framework for CFCs. What does this mean, it handles dependencies. For example, if you have a userService that needs (depends on) an userDAO instead of having to initiate the components(beans) via CF code in the right order like:

[*** More ***]

BlogCFC was created by Raymond Camden / Contact Blog Owner / mptooling.com / spicemerchants-portsmouth.co.uk / ipicture.it