Blog

Luis Majano

March 24, 2022

Spread the word


Share your thoughts

ColdSpring was the first dependency injection framework for ColdFusion in the good 'ol days. It was inspired by Java Spring and it rocked during its tenure. As a matter of fact, there is still quite a large number of applications leveraging it, even though the framework itself is completely legacy, unsupported and might not even work on some versions of Adobe 2018+ as well. If you are in this technical debt boat and want a quick win and recover some ground in the technical debt war, then this tutorial is for you.

WireBox

WireBox is an enterprise ColdFusion Dependency Injection and Aspect Oriented Programing (AOP) framework. WireBox's inspiration has been based on the idea of rapid workflows when building object oriented ColdFusion applications, programmatic configurations and simplicity. With that motivation we introduced dependency injection by annotations and conventions, which has been the core foundation of WireBox.

WireBox is standalone framework for ColdFusion (CFML) applications and it is also bundled with the ColdBox Platform.

What's even more important its that WireBox is:

Installing WireBox into your legacy application is super easy using our CLI tool called CommandBox:

box install wirebox

This command will download the latest version of WireBox and create a folder called wirebox for you. You can then maintain that dependeny or more using CommandBox.

// Creates wirebox and places it in application scope: application.wirebox
new wirebox.system.ioc.Injector();

Let's Convert!

If you have an application that leveraged ColdSpring for your dependency injection, you can easily port it to WireBox. The first step is converting the ColdSpring XML file to a WireBox Binder. This will translate 1-1 the bean configurations to WireBox configurations. After that, it's a matter of testing your objects and switching the references to the ColdSpring bean factory to application.wirebox.getInstance( "BeanName" ).

After that, you can decide if you want to keep the object configurations as is, or you can start refactoring them by using our conventions instead of configuration approach. Especially if you love annotations in your code.

ColdSpring XML to WireBox DSL

Make sure you have CommandBox CLI installed as we will be using it to convert our XML file to WireBox DSL. Now it's time to install our module that converts ColdSpring XML to WireBox DSL:

box install commandbox-coldspring-to-wirebox

This will install the coldspring-to-wirebox command into your CLI. You can get help by issuing a coldspring-to-wirebox --help command. However, it's very easy to use:

# Produces a WireBox.cfc where you run the command
coldspring-to-wirebox tests/coldspring.xml.cfm

# Stores the WireBox.cfc in the same location as the file above
coldspring-to-wirebox tests/coldspring.xml.cfm tests/WireBox.cfc

That's it! This will convert all your definitions and you are ready to roll!

Test Your Binder

We can now instantiate a new instance of WireBox with this Binder and use it!

new wirebox.system.ioc.Injector( "tests/WireBox" );

// Get an instance!
application.wirebox.getInstance( "MyOldBean" );

Right now would be a great time to create some canary integration tests using TestBox which can verify that your objects can be created and wired up correctly. This will be a huge help to get you started on the road to better test coverage and migrating your legacy elephant to modern times:

component extends="testbox.system.BaseSpec"{

     // executes before all suites
     function beforeAll(){
          wirebox = new wirebox.system.ioc.Injector( "path.to.Binder" );
     }

     // executes after all suites
     function afterAll(){
          structDelete( application, "wirebox" );
     }

     // All suites go in here
     function run( testResults, testBox ){
          describe( "UserService", () => {

               it( "can be created and wired", () => {
                    var target = wirebox.getInstance( "UserService" );
                    expect( target ).toBeComponent();
                    expect( target.getUserDAO() ).toBeComponent();
               } );

          } );
     }

}

Add Your Comment

Recent Entries

BoxLang 1.0.0 Beta 7 Launched

BoxLang 1.0.0 Beta 7 Launched

We are pleased to announce the release of BoxLang 1.0.0-Beta 7! This latest beta version includes improvements and essential bug fixes, but more importantly it certifies the execution of ColdBox HMVC and TestBox.

What is BoxLang?

BoxLang is a modern dynamic JVM language that can be deployed on multiple runtimes: operating system (Windows/Mac/*nix/Embedded), web server, lambda, iOS, android, web assembly, and more. BoxLang combines many features from different progr

Luis Majano
Luis Majano
July 26, 2024
New BoxLang Feature: Java Method References and Higher-Order Functions

New BoxLang Feature: Java Method References and Higher-Order Functions

We’ve added more goodies to our BoxLang Java interop: method references and higher-order functions. CFML has never let you do these things, making Java Interop feel like a second-class citizen. But with BoxLang, we’re elevating Java integration to a new level.

Maria Jose Herrera
Maria Jose Herrera
July 26, 2024
Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Are you a CFML developer looking to take your skills to the next level? Look no further than the ColdBox from Zero to Hero Virtual Live Training! This intensive two-day course will equip you with the knowledge and expertise to build robust and scalable applications using ColdBox 7, the latest version of the most popular CFML MVC framework.

What You'll Learn:

  • Master the Fun...

Cristobal Escobar
Cristobal Escobar
July 24, 2024