No two people are exactly alike and the same can be said of applications. However, the same way people have similar traits so too can applications. When I am developing with ColdFusion, ColdBox is my go-to tool to get things done quickly. I thought it might be helpful to outline how I get up and running.

Application Scaffolding with CommandBox

Scaffolding the application with CommandBox

The first step is scaffolding the application. In the past I would clone the latest ColdBox release, but nowadays I just create my application directory and create the application structure with box coldbox create app. This method leverages CommandBox to  download the latest ColdBox release and generate the bones of the application with the advanced script template. Next it is time to start the embedded server with box server start. By default this will spin up a new Lucee server on a random port, but it is easy enough to spin up an Adobe ColdFusion instance by adding the cfengine=adobe parameter when starting the server.

Application.cfc

Copying the database configuration

The next thing I do is log in to the Lucee server administrator and configure any application specific settings. Depending on the requirements there are two options; If I just need to set the default datasource I will configure it in the Lucee server administrator, copy the datasource configuration and paste it into Application.cfc. If more granular control is required, use cfconfig to export the server configuration to a JSON file. The embedded server does not retain is configuration when it is restarted unless you have exported your settings. If not, you will have to reconfigure each restart.

RequestContextDecorator.cfc

RequestContextDecorator.cfc

The next thing I do is create a request context decorator. If you are not familiar with request context decorators, it allows you to decorate your rc and prc scopes; If you want to ensure a value is defined every request, this is a good place to put it. You could opt to put it in the onRequestStart handler in Main.cfc, but it seems cleaner to use the decorator pattern.

This is where data I will need on every request is defaulted such as menu data, page meta data, and things like that. I usually will create a prc['jsonData'] structure where I can set any values I want to reference from javascript. For instance, if I set prc['jsonData']['pageTitle'] = "My awesome page"; it can be easily referenced in javascript using window.jsData.pageTitle . It also prevents having to wrap all my javascript code in  <cfoutput> tags.

Coldbox.cfc

Adjusting Coldbox.cfc

That done, it is time to move on to Coldbox.cfc and set the application name and the reinit password. If I am leveraging the request context decorator I will configure it here under the extension point settings. Any variables needed across the entire application are stored in the  settings structure allowing them to be referenced where needed using injection (property name="customSetting" inject="coldbox:setting:customSetting";).

Wirebox.cfc

Setting scan locations for Wirebox

Next I configure the Wirebox scan locations. This is an array of folders where Wirebox should look for components. You can skip this step if you prefer to create instances manually (var myService = new models.services.MyService();), but I like creating a property (property name="MyService" inject="model";) and having Wirebox inject it for me.

Layouts/Main.cfm

Bootstrap prc.jsonData to the layout

The final step is bootstrapping any JSON data to the page by serializing the prc.jsonData that was defaulted in the request context decorator and putting that in the <head> of the layout.

Closing Thoughts

There may be some minor differences in how each application is setup, but for the most part this is my core configuration. This does not cover all the bells and whistles that CommandBox provides since it is easy to add different application aspects. Would you like the ability to render markdown as HTML? Install the ColdBox markdown module with box install cbmarkdown. Does your application allow user input and you want to prevent XSS attacks? Add the OWASP AntiSamy module with box install cbantisamy. Need Javaloader? All you have to do is box install cbjavaloader.

And that is just scratching the surface.

At any rate, that is how I get my ColdBox applications up and running. I am always interested in finding out how other developers get their environment setup so please leave a comment.