Accessibility

Table of Contents

An introduction to ColdFusion frameworks

Frameworks to Manage ColdFusion Components

Imagine you have been writing your application using a MVC framework, and it's going along very well. You have also started placing some ColdFusion Components (CFCs) in your Application scope so you can access them readily without recreating them on every request. So far you have five CFCs in your Application scope, and that has been manageable, but as you develop it looks like you will have ten, and then thirty! Several of these CFCs require each other to work, and you start to realize that as you attempt to juggle creating all these CFCs and their dependencies when your application starts up your Application.cfc is looking much like the spaghetti code you were trying to avoid in the first place.

Before things get too crazy, you can implement a dependency injection framework. Now when you need a CFC, you simply ask for it from the framework, and it hands it to you. You no longer have to worry about what relationships it has to other CFCs, and what order they get created, and it doesn't matter if you have ten, twenty, or one hundred CFCs, you know they will always be managed for you.

ColdSpring and LightWire are dependency injection frameworks that are commonly in use in the ColdFusion community.

ColdSpring

ColdSpring was the first dependency injection framework for ColdFusion. Taking much of its inspiration from the Java Spring project, it uses an XML file to enable you to configure your CFCs and their dependencies. These dependencies can be explicitly set, or if ColdSpring is set to autowire it will introspect the meta-data of each CFC it instantiates and resolve the dependencies automatically.

Once your XML file has been configured correctly, you simply request CFCs by the name specified in configuration, and ColdSpring manages the instantiation of the object as well as any dependencies along the way.

While ColdSpring manages dependency injection, it also provides functionality for aspect-oriented programming, which enables you to wrap code blocks before, after, or around different parts of already implemented CFC functions at run time. With ColdSpring aspect-oriented programming you can also use RemoteProxyFactories for exposing services to remote invocations.

More information about ColdSpring, visit http://www.coldspringframework.org.

LightWire

LightWire is another dependency injection framework. Unlike ColdSpring, it also provides a programmatic interface in addition to allowing configuration through XML. This can be useful if you are not very familiar with XML, and simply want to use regular ColdFusion to outline your object dependencies.

While LightWire does not provide any additional functionality above and beyond dependency injection, it is a very lightweight framework. With only two CFCs, LightWire can be integrated and deployed easily with almost any project and with a minimum of overhead.

For more information on LightWire, visit http://lightwire.riaforge.org/.