Getting Started With LightWire

To get started with LightWire download the LightWire.cfc and the sample LightWireConfig.cfm from the SVN repository. You can place either file anywhere you want. I personally put the cfc in .com.lib (my library directory) and the config file in a "config" directory both of which are below my web root for a given project, but you can put the files anywhere you want.

Somewhere in your Application.cfc (in the onApplicationStart method) you’ll want to set the path to the LightWire config file path and then createobject LightWire. I currently just create it in application scope. Below is the config code I use which happens to use an application.CFMapping for the application specific mapping.

<cfset Local.ConfigFilePath = "/#application.CFMapping#/config/LightWireConfig.cfm">
<cfset Application.LightWire = CreateObject("component","").Init(Local.ConfigFilePath)>

You will want to customize the config file. See my recent posting on the syntax for that.

That is just about it. If you want to create an object (transient or singleton), just call LightWire and it will return the fully loaded object. Below are a couple of sample requests. If you want a singleton, use getSingleton(). If you want a transient, getTransient(). All you need to pass in is the name of the class you want to instantiate.

<!--- Create PageService --->
<cfset Request.PageService = Request.LightWire.getSingleton("PageService")>

<!--- Create PageObject --->
<cfset Request.PageObject = Request.LightWire.getTransient("PageObject")>

I could have created a single get() method as it would be easy to tell from the config file whether it was a singleton or a transient, but I decided I’d rather have a really explicit interface which would make it very obvious in my code what I was doing. Please also bear in mind that most objects will just be direct injected, so a lot of things like PageService and PageDAO won’t ever be explicitly called – they’ll just be injected into the appropriate controller cfcs so in practice you only need to call LightWire occasionally (pretty much wherever you'd have called ColdSpring plus wherever you'd have called your custom bean factories if you need DI into the beans).

If you are new to DI/IoC, start off by downloading ColdSpring. It has better documentation, more support and many more people using it. LightWire is for people who have explored ColdSpring and have decided they’d like an approach more optimized for DI into transient objects and/or because they like programmatic config files.

Any comments/thoughts much appreciated!

Nick Tong's Gravatar Hi Peter, Maybe a short explanation of what a singleton and transient object might help people understand the code above a little more - just a thought?
# Posted By Nick Tong | 2/6/07 1:25 PM
Peter Bell's Gravatar Hi Nick,

Great cooment, and good point - thanks. There are some cfc's that you only need to create once. In effect they act as function libraries which may also contain some "global" variables (although hidden within the cfc). Examples of this would be a UserService for interactive with users (when you want to get a list of users, for instance), or a UserDAO for holding the SQL to get users from a database. These objects can just be created once and effectively stored within the application scope (although that is hidden and handled by Lightwire). These are "singleton" objects because you only need a single object for each of these.

Transient objects are those which live for a shorter period of time and which you may well create multiple times. For instance, if you were to get a list of users from the database for a particular user request, you might want to encapsulate that recordset in an object. That would be a transient object as its only job is to take the user list from the model and to pass it to the view. At the end of the page request the object is thrown away and then if you want a list of users down the line, you'll go back to the UserService and it'll give you a new user colleciton with the appropriate recordset.

So, a singleton is typically created once for the life of an application whereas transients are created and disposed of much more frequently - often on a per request basis.
# Posted By Peter Bell | 2/6/07 1:36 PM
Aaron Roberson's Gravatar Peter,

I am enjoying LightWire very much!

I am wondering though, should I scope all of my objects in the application or should I just call them in my controller when I need them? If it makes a difference, I am using Lazy Loading.
# Posted By Aaron Roberson | 2/26/07 7:33 PM
Peter Bell's Gravatar Hi Aaron,

Glad you're enjoying! Of those two approaches, just call the objects from LightWire. Put l/w into app scope and if you want UserService just write: UserService = application.LightWire.getSingleton("UserService").

However, here is something to think about. Why don't you just use LightWire to create your controllers and then inject the service methods into the controllers using LightWire so you don't need to call LightWire at all in the controller?! That's how I'm doing things in LightBase and it seems to be working out pretty well.
# Posted By Peter Bell | 2/27/07 10:17 AM
nick tong's Gravatar Hi Peter, this sounds interesting, do you have an example?? (I feel a blog post coming ;))
# Posted By nick tong | 2/27/07 10:25 AM
Aaron Roberson's Gravatar Blog Post... encore!

First off, I'm not even sure how to use a controller as a cfc. I usually just have a .cfm page with a prefix and the name of the calling page and do all of my traffic control there.
# Posted By Aaron Roberson | 2/27/07 10:30 AM
Peter Bell's Gravatar Hi Nick,

Lets say you want to run the Cart controller. You'd say Cart = application.LightWire.get("Cart"). In your config file, you'd inject (say) product, cart and user services to the Cart controller (or whatever it needed). Then in the cart controller if you wanted to get product info you'd call ProductService.getbyID("CartProductID") and if you wanted to save your cart you'd do something like Does that make any sense?
# Posted By Peter Bell | 2/27/07 10:36 AM
Peter Bell's Gravatar Aaron, Understood. Then stick with what is working for now and just call the cfc's using application.LightWire.getSingleton(ServiceMethodName) - moving your controllers to cfcs as well is the next step, but no compelling reason to jump in and do that today!
# Posted By Peter Bell | 2/27/07 10:37 AM
nick tong's Gravatar Perfectly, i just need to put it into practice to make it gel.
# Posted By nick tong | 2/27/07 11:14 AM
Aaron Roberson's Gravatar The controller CFC would be a transient, right?

I've wanted to go to using CFCs for my controllers for a long while, I just can't find any resources on learning to do so. I probably know enough already to do it, I just haven't really tried it yet and seeing some code would probably help get me over the edge.
# Posted By Aaron Roberson | 2/27/07 4:50 PM
Peter Bell's Gravatar I'll try to post somesample LightBase code as this is the approach I take there.

You *could* make the controllers transient, but I don't keep any state in my controllers, so I treat them as singletons so I don't need to re-init them every time.
# Posted By Peter Bell | 2/27/07 5:09 PM
Aaron Roberson's Gravatar Great! That would be much appreciated!
# Posted By Aaron Roberson | 2/27/07 5:19 PM
buy FFXI Gil's Gravatar The website sells the kinds of game gold, you can buy in here, and you can find the gold is very cheap.
# Posted By buy FFXI Gil | 4/27/09 10:45 PM
GuildWars Gold's Gravatar I really like your post, thanks for sharing.
# Posted By GuildWars Gold | 4/28/09 1:35 AM
cheap wonderland online Gold's Gravatar the site is good
# Posted By cheap wonderland online Gold | 4/28/09 2:57 AM
cheap mesos's Gravatar i like it
# Posted By cheap mesos | 4/28/09 4:14 AM
dong's Gravatar Sergio dos Santos, international Marketing Assistant for Ankama Games, sat down with me recently and I have to admit, I find myself looking forward to Wakfu more now than ever!
# Posted By dong | 4/28/09 5:32 AM
ccc's Gravatar [url=://]world of warcraft power leveling[/url] [url=://]wow power leveling[/url] [url=://]power leveling[/url] [url=://]wow gold[/url] [url=://]????[/url] [url=://]paper cup machine[/url] [url=://]Mass air flow[/url] [url=://]?????[/url] [url=://]????[/url] [url=://]????[/url] [url=://]???[/url] [url=://]automatic rigid box line[/url] [url=://]paper converting and wrapping machines[/url] [url=://]automatic box makers[/url] [url=://]rigid set-up gift box[/url],[url=://]paperboard converting equipment[/url]

[url=://]????[/url] [url=://]?????[/url] [url=://]????[/url] [url=://]?????[/url] [url=://]?????[/url] [url=://]????[/url] [url=://]????[/url] [url=://]????[/url] [url=://]?????[/url] [url=://]?????[/url] [url=://]?????[/url] [url=://]?????[/url] [url=://]?????[/url] [url=://]?????[/url] [url=://]???[/url] [url=://]?????[/url] [url=://]?????[/url] [url=://]thermoforming Equipment[/url] [url=://]bag making machine[/url] [url=://]????[/url] [url=://]????[/url] [url=://]??[/url] [url=://]??????[/url] [url=://]???[/url] [url=://]???[/url] [url=://]?????[/url] [url=://]????[/url]

[url=://]power leveling[/url] [url=://]wow power leveling[/url] [url=://]paper box[/url] [url=://]paper box equipment[/url] [url=://]thermoforming Equipment[/url] [url=://]Plastic Machinery[/url] [url=://]Plastic Machine[/url] [url=://]??[/url] [url=://]????[/url] [url=://]???[/url]
# Posted By ccc | 5/5/09 10:23 PM
asdf's Gravatar <a href="://">world of warcraft power leveling</a> <a href="://">wow power leveling</a> <a href="://">power leveling</a> <a href="://">wow gold</a> <a href="://">????</a> <a href="://">????</a> <a href="://">paper cup machine</a> <a href="://">Mass air flow</a> <a href="://">?????</a> <a href="://">????</a> <a href="://">????</a> <a href="://">???</a> <a href="://">automatic rigid box line</a> <a href="://">paper converting and wrapping machines</a> <a href="://">automatic box makers</a> <a href="://">rigid set-up gift box</a>,<a href="://">paperboard converting equipment</a>

<a href="://">????</a> <a href="://">?????</a> <a href="://">????</a> <a href="://">?????</a> <a href="://">?????</a> <a href="://">????</a> <a href="://">????</a> <a href="://">????</a> <a href="://">?????</a> <a href="://">?????</a> <a href="://">?????</a> <a href="://">?????</a> <a href="://">?????</a> <a href="://">?????</a> <a href="://">???</a> <a href="://">?????</a> <a href="://">?????</a> <a href="://">thermoforming Equipment</a> <a href="://">bag making machine</a> <a href="://">????</a> <a href="://">????</a> <a href="://">??</a> <a href="://">??????</a> <a href="://">???</a> <a href="://">???</a> <a href="://">?????</a> <a href="://">????</a>

<a href="://">power leveling</a> <a href="://">wow power leveling</a> <a href="://">paper box</a> <a href="://">paper box equipment</a> <a href="://">thermoforming Equipment</a> <a href="://">Plastic Machinery</a> <a href="://">Plastic Machine</a> <a href="://">??</a> <a href="://">????</a> <a href="://">???</a>
# Posted By asdf | 6/4/09 1:35 AM
wow gold's Gravatar ://
# Posted By wow gold | 6/9/09 3:18 AM
Sho Online gold's Gravatar As a new player , you may need some game guides or information to enhance yourself.
<a href="://">Sho Online Mun</a> is one of the hardest theme for every class at the beginning . You must have a good way to manage your <a href="://">Sho Mun</a>.If yor are a lucky guy ,you can earn so many <a href="://">Sho Online gold</a>
by yourself . But if you are a not , I just find a nice way to <a href="://">Sho gold</a>. If you need , you can buy <a href="://">buy Sho Online gold</a>
at our website . Go to the related page and check the detailed information . Once you have any question , you can connect our customer service at any time .
# Posted By Sho Online gold | 6/29/09 2:52 AM
Dunk SB Shoes's Gravatar great post!t thank you!
# Posted By Dunk SB Shoes | 7/12/09 1:15 PM
tiffanys's Gravatar It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of

post. I will be your loyal reader. Thanks again.
# Posted By tiffanys | 7/14/09 9:46 PM
links of london's Gravatar Thanks for your comments!
# Posted By links of london | 7/15/09 9:16 PM
cheap nike shoes's Gravatar like it much
# Posted By cheap nike shoes | 7/20/09 2:43 AM
wholesale nike shoes's Gravatar haha ,let me bookmark it
# Posted By wholesale nike shoes | 7/20/09 2:44 AM
tiffany and co's Gravatar Make clearly to find the perfect bridal bracelets to ending off your, something

old with a, something new, per say. Because the last touch that will meet. With honeymoon

post. I will be your loyal reader. Thanks again.
# Posted By tiffany and co | 7/20/09 3:10 AM
coach purses's Gravatar so nice ,it is good
# Posted By coach purses | 7/20/09 10:02 AM
chanel purses's Gravatar haha,nice
# Posted By chanel purses | 7/20/09 10:03 AM
links of london's Gravatar I am agreet with!
# Posted By links of london | 7/20/09 10:27 PM
ed hardy's Gravatar Thanks for your commments!
# Posted By ed hardy | 8/3/09 9:52 PM
yuii's Gravatar 091030115347AM<a href="://">Silkroad Gold</a> | <a href="://">SRO Gold</a> | <a href="://">Silkroad online gold</a> | <a href="://">silkroad powerleveling</a> |
# Posted By yuii | 10/29/09 11:53 PM
Ed Hardy's Gravatar Good information!
# Posted By Ed Hardy | 12/17/09 10:08 PM
rolex's Gravatar There are many website selling <A href="://" title="replica watches">replica watches</A> but how to chose a good one is very important.Here is a good one for you.It is also my friend tell me that.they have many good and cheaper Bertling,Omega and <A href="://" title="rolex replica">rolex replica</A>
# Posted By rolex | 6/28/10 1:25 AM
rolex's Gravatar yes,I am sure you will like that.
# Posted By rolex | 6/28/10 1:27 AM
hn's Gravatar <a href="://">Retro Air Jordan</a>
# Posted By hn | 7/1/10 9:16 PM
rose's Gravatar It's quite interesting.I will look around for more such post.Thanks for sharing
:// Ed Hardy Australia
:// ED Hardy Clothing
# Posted By rose | 8/30/10 8:02 AM
Henrry1987's Gravatar Currently featured replica breitling are available in your own most beautiful replica omega and glamorous replica iwc shops online within most affordable replica watches.Certainly you have a lot of replica rolex choices to buy your own replica breitling.You can pay small money for all types of replica omega so as to change your own style matchlessly.With the purchasing of cheap replica watches,you would be instantly able to grab few benefits on the replica iwc such as improved behavior,charming look,increased self esteem,enhanced charisma,and smiley face.That is why replica omega have become one of the most symbolic fashion replica bvlgari accessories today.

Are you interested in any featured fashion replica watches?Do you instantly want to grab a famous brand replica breitling?If yes,then please buy replica hublot because replica omega are one of the most beautiful replica watches and innovative replica cartier in the worldwide replica breitling market most recently.That is why everyone is inclining towards trendy replica tag heuer nowadays.They are very distinctive fake watches, durable replica cartier,dependable replica tag heuer and affordable fake watches.Breitling replica omega contain vivid yet versatile colors,designs and logos that would attract to the eyes of every young man and woman on the dot.Currently replica breitling have become a huge symbol of fashion replica watches especially for the hot replica rolex,glamorous replica breitling and fashionable replica omega worldwide.They particularly buy replica watches so as to change their own appearance,shape and figures stunningly.That is why fashion replica rolex suit to the styles of the feminists always.

If you want to buy replica watches,you will have to make a quick research on replica rolex on the Google as you will go through a list of top replica breitling companies over there and choose your 100% professional company out of the all replica omega. Moreover replica watches are very comfortable fashion replica omega accessories.That is why replica breitling do not cause any sort of agony or depression to you at all.Stunningly online replica watches industry makes you available discounted replica omega globally.In short,Breitling replica breitling are very trendy,peaceful replica watches and lovable fashion replica omega accessories.replica breitling are very affordable,dependable replica watches and unique replica omega.That is why everyone is inclining towards cheap designer replica breitling nowadays so as to fulfill his or her modern day needs and desires matchlessly.Amazingly online fake watches shop offers you full color replica hublot worldwide in a most dedicated replica iwc,affordable replica watches and reliable replica omega.So please don't miss this replica breitling opportunity to buy your own unique replica watches at all.Come to our replica watches brand store.choose replica iwc and fake watches.Our best-sell replica iwc is replica audemar piguet.So I suggested!
# Posted By Henrry1987 | 10/19/10 5:04 AM
Coffee vending machine chennai's Gravatar <a href="://" title="Coffee vending machine chennai">Coffee vending machine chennai</a>
# Posted By Coffee vending machine chennai | 3/23/11 4:43 AM
Paper cups machines's Gravatar Its a very nice blog..
# Posted By Paper cups machines | 3/26/11 3:47 AM
coffee vending machines chennai's Gravatar really nice blog.very useful information provide by you.I bookmark it.....
# Posted By coffee vending machines chennai | 3/27/11 11:38 PM
angelinamathew's Gravatar Superb task ! Your blog has given me most of the information and facts I requested .
<a href="://">Locksmith Kendall</a>
# Posted By angelinamathew | 4/24/11 11:39 PM
Non woven printing machine's Gravatar Thanks for such a great post, I am totally impressed! Keep stuff like this coming.
# Posted By Non woven printing machine | 10/28/11 4:41 AM
Guojuicycoutureout's Gravatar :// coach factory outlet
:// coach outlet online
:// coach outlet
:// coach outlet online
:// juicy couture outlet online
:// Coach outlet store online
:// Coach outlet online
:// coach outlet store online
# Posted By Guojuicycoutureout | 11/27/11 10:22 PM
Dieta de 21 dias's Gravatar I really liked your content.
# Posted By Dieta de 21 dias | 11/26/16 7:37 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.5.006. | Protected by Akismet | Blog with WordPress