Playing with ColdBox request context decorators

I am working on a project that will eventually require a login. That being said, it would be nice to always have information for the currently logged in person stored in the PRC. ColdBox has a built in class fittingly called RequestContextDecorator which will easily handle this.

Here is a basic request context decorator:

There is not a lot going on here but I will cover the basics. First, a request context decorator must extend coldbox.system.web.context.RequestContextDecorator. Next a configure() method is required that will modify how the request contexts behave once they are created. Getting the original request context is handled by calling the getRequestContext() function and additionally you can get the private RC by calling getRequestContext(private = true).

Now you can modify the RC and PRC with any values you like. For extra points I have included getting ColdBox settings as well as getting an instance of a service through Wirebox.


4 thoughts on “Playing with ColdBox request context decorators

  1. So this could be put in onRequestStart handler as well? (the one you setup in Coldbox config). I’d be curious as to the pros/cons of these 3 or does it really not matter and just personal prefernce?

    1. Sorry Andy, I guess I kinda forgot that piece. In the Coldbox.cfc there is actually a setting where you would provide the path to your request context cfc. Coldbox will run the decorator with each request.

      As far as pros/cons, interceptors/decorators are the Coldbox way of doing things although hooking into onRequestStart would definitely work.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s