<?xml version="1.0" encoding="utf-8"?>

			<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">

			<channel>
			<title>Brian Kotek: Inversion of Control - Swiz</title>
			<link>http://www.briankotek.com/blog/index.cfm</link>
			<description>Brian Kotek on ColdFusion, Flex, AIR, Java, Groovy, Design Patterns, and Object-Oriented Programming</description>
			<language>en-us</language>
			<pubDate>Tue, 07 Sep 2010 10:58:59 -0700</pubDate>
			<lastBuildDate>Mon, 16 Aug 2010 13:12:00 -0700</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>brian428@briankotek.com</managingEditor>
			<webMaster>brian428@briankotek.com</webMaster>
			<itunes:subtitle></itunes:subtitle>
			<itunes:summary></itunes:summary>
			<itunes:category text="Technology" />
			<itunes:category text="Technology">
				<itunes:category text="Podcasting" />
			</itunes:category>
			<itunes:category text="Technology">
				<itunes:category text="Tech News" />
			</itunes:category>
			<itunes:keywords></itunes:keywords>
			<itunes:author></itunes:author>
			<itunes:owner>
				<itunes:email>brian428@briankotek.com</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			
			<itunes:explicit>no</itunes:explicit>
			
			
			
			
			
			<item>
				<title>Swiz Example Application Demonstrating Module Support</title>
				<link>http://www.briankotek.com/blog/index.cfm/2010/8/16/Swiz-Example-Application-Demonstrating-Module-Support</link>
				<description>
				
				I just pushed a new sample application called &lt;a href=&quot;http://github.com/swiz/swiz-examples/tree/master/SwizModuleExample-Flex4/&quot; target=&quot;_blank&quot;&gt;SwizModuleExample-Flex4&lt;/a&gt; to GitHub. This example is meant to demonstrate the various ways that Swiz supports the use of modules. The key ideas demonstrated are:

&lt;ul&gt;
&lt;li&gt;Loading a Module&lt;/li&gt;
&lt;li&gt;Detecting full creation of a Module (not just the ModuleEvent.READY event)&lt;/li&gt;
&lt;li&gt;Dispatching events from a root Swiz instance that are mediated by all Modules&lt;/li&gt;
&lt;li&gt;Dispatching events from a root Swiz instance to a specific Module&lt;/li&gt;
&lt;li&gt;Dispatching events from a Module that are mediated in the root Swiz instance&lt;/li&gt;
&lt;li&gt;Dispatching events from a Module that are mediated by other Modules.&lt;/li&gt;
&lt;li&gt;Injecting Beans that are defined in a root Swiz instance into a child Swiz instance.&lt;/li&gt;
&lt;/ul&gt;

While this example is really meant to be looked through at the code level, I have a &lt;a href=&quot;http://www.briankotek.com/blog/files/swiz_modules_example/Main.html&quot; target=&quot;_blank&quot;&gt;running version with View Source enabled&lt;/a&gt; that you can look at as well. I hope folks find this example helpful!
				
				</description>
				
				
				<category>Flex</category>
				
				<category>Swiz</category>
				
				<pubDate>Mon, 16 Aug 2010 13:12:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2010/8/16/Swiz-Example-Application-Demonstrating-Module-Support</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>CFUnited Clean Code and Swiz Presentations Now Online</title>
				<link>http://www.briankotek.com/blog/index.cfm/2010/8/4/CFUnited-Clean-Code-and-Swiz-Presentations-Now-Online</link>
				<description>
				
				Just a quick note that, as promised, my presentations from CFUnited are now online!

&lt;a href=&quot;http://slidesix.com/view/Brian-Kotek--Clean-Code--CFUnited-2010&quot; target=&quot;_blank&quot;&gt;Clean Code&lt;/a&gt;

&lt;a href=&quot;http://slidesix.com/view/Brian-Kotek--Swiz--CFUnited-2010&quot; target=&quot;_blank&quot;&gt;The Swiz Framework for Flex and ActionScript&lt;/a&gt;

Thanks to all who attended!
				
				</description>
				
				
				<category>Development</category>
				
				<category>Flex</category>
				
				<category>Conferences</category>
				
				<category>Presentations</category>
				
				<category>Swiz</category>
				
				<pubDate>Wed, 04 Aug 2010 15:33:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2010/8/4/CFUnited-Clean-Code-and-Swiz-Presentations-Now-Online</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Using the Swiz AutowiredTestCase</title>
				<link>http://www.briankotek.com/blog/index.cfm/2010/6/15/Using-the-Swiz-AutowiredTestCase</link>
				<description>
				
				One of the utility classes that is part of the Swiz library is AutowiredTestCase. As the name implies, you can use this class to help test your Swiz applications. 

In this case, code will show what&apos;s going on much better than doing a lot of typing, so here is a sample FlexUnit 4 test case. First, the class under test:

&lt;code&gt;js|
package com.briankotek.flex4swiztests.control
{
	import com.briankotek.flex4swiztests.event.MyEvent;
	import flash.events.IEventDispatcher;

	public class MyController
	{
		
		[Dispatcher]
		public var dispatcher : IEventDispatcher;
		
		public var didSomething : Boolean = false;
		
		[Mediate( event=&quot;MyEvent.CONTROLLER_ACTION_REQUESTED&quot; )]
		public function handleAction() : void
		{
			didSomething = true;
			actionComplete();
		}
		
		private function actionComplete() : void
		{
			dispatcher.dispatchEvent( new MyEvent( MyEvent.CONTROLLER_ACTION_COMPLETE ) );
		}
		
	}
}
&lt;/code&gt;

You can see this is a simple controller, which responds to the CONTROLLER_ACTION_REQUESTED event, updates a property, and then dispatches CONTROLLER_ACTION_COMPLETE. We want to test that the controller is responding to the correct event, property updating the property, and finally dispatching the completion event.

The event itself is a simple event class:

&lt;code&gt;js|
package com.briankotek.flex4swiztests.event
{
	import flash.events.Event;
	
	public class MyEvent extends Event
	{
		public static const CONTROLLER_ACTION_REQUESTED : String = &quot;controllerActionRequested&quot;;
		public static const CONTROLLER_ACTION_COMPLETE : String = &quot;controllerActionComplete&quot;;
		
		public function MyEvent(type:String)
		{
			super(type, true, false);
		}
	}
}
&lt;/code&gt;

Finally, the test case itself:

&lt;code&gt;js|
package com.briankotek.flex4swiztests.control
{
	import com.briankotek.flex4swiztests.control.MyController;
	import com.briankotek.flex4swiztests.event.MyEvent;
	import org.flexunit.Assert;
	import org.flexunit.async.Async;
	import org.swizframework.core.*;
	import org.swizframework.utils.test.AutowiredTestCase;

	public class MyControllerTestCase extends AutowiredTestCase
	{	
		private var myController : MyController;
		
		[Before]
		public function setUp():void
		{
			myController = new MyController();
			
			swizConfig = new SwizConfig();
			swizConfig.eventPackages = &quot;com.briankotek.flex4swiztests.event.*&quot;;
			
			beanProviders = [new BeanProvider( [myController] )];
		}
		
		[After]
		public function tearDown():void
		{
			myController = null;
		}
		
		[Test(async)]
		public function testControllerActionRequested() : void
		{
			Assert.assertTrue( &quot;Controller property is already true.&quot;, myController.didSomething == false );	
			Async.handleEvent( this, swiz.dispatcher, MyEvent.CONTROLLER_ACTION_COMPLETE, checkEvent ); 
			swiz.dispatcher.dispatchEvent( new MyEvent( MyEvent.CONTROLLER_ACTION_REQUESTED ) );
		}
		
		private function checkEvent( event : Event, passThroughData : Object ) : void
		{
			Assert.assertTrue( &quot;Controller property was not updated.&quot;, myController.didSomething == true );	
		}
		
	}
}
&lt;/code&gt;

I start off setting up an instance of Swiz that my test can use. AutowiredTestCase has a method marked with [Before] metadata, so that FlexUnit runs it before each test. I create an instance of the class under test (MyController), then set the event packages on the SwizConfig. Finally, I place the MyController instance into a BeanProvider, so that Swiz will process it as a bean. This way, any Swiz metadata in MyController is processed.

The test method dispatches a CONTROLLER_ACTION_REQUESTED event. If all goes well, the mediated event in the controller should run, update the property, and then the controller will dispatch the completion event. Running the test produces a passing result, so everything is working as expected!

Note that because Swiz actually processes your test case itself as a bean, you can use Swiz metadata in your test if you want or need to. So injecting a dispatcher, mediating an event, or testing custom metadata processors are all possible as well.
				
				</description>
				
				
				<category>Unit Testing</category>
				
				<category>Flex</category>
				
				<category>Swiz</category>
				
				<pubDate>Tue, 15 Jun 2010 09:27:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2010/6/15/Using-the-Swiz-AutowiredTestCase</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Swiz 1.0RC Released! So here&apos;s an updated example, custom ViewMediator, and more</title>
				<link>http://www.briankotek.com/blog/index.cfm/2010/5/19/Swiz-10RC-Released-So-heres-an-updated-example-custom-ViewMediator-and-more</link>
				<description>
				
				There&apos;s a lot of good news from the Swiz world today. First, we just released the &lt;a href=&quot;http://github.com/swiz/swiz-framework/zipball/v1.0.0-RC1&quot; target=&quot;_blank&quot;&gt;Swiz 1.0 Release Candidate&lt;/a&gt;, which fixes a number of small bugs in the beta and adds numerous new features. This version should be pretty much feature-complete, so at this point we&apos;ll be focused on fixing any issues that come up. A final 1.0 should be out in the next few weeks.

I did my best to help out with this release by working hard on updated documentation. You can see the fruits of this labor on the new &lt;a href=&quot;http://swizframework.jira.com/wiki/display/SWIZ/Home&quot; target=&quot;_blank&quot;&gt;Swiz documentation wiki&lt;/a&gt; we&apos;ve created through JIRA Studio. You can also sign up to enter feature requests or bugs, vote on issues, and all the other good stuff that JIRA provides. If you have any feedback on the documentation, feel free to leave a wiki comment and we&apos;ll do our best to address it.

I&apos;ve also created a &lt;a href=&quot;http://www.briankotek.com/blog/files/swiz_10_rc_example/Main.html&quot; target=&quot;_blank&quot;&gt;Swiz 1.0RC version of my example application&lt;/a&gt;. If you like, you can &lt;a href=&quot;http://www.briankotek.com/blog/files/swiz_10_rc_example/srcview/index.html&quot; target=&quot;_blank&quot;&gt;view or download the source code&lt;/a&gt;. 


Since 1.0RC removes the option for &quot;view injection&quot; into a bean, folks have asked about ways to handle providing a view to a Swiz bean. I created a &lt;a href=&quot;http://wiki.github.com/brian428/swiz-viewmediatorlib/&quot; target=&quot;_blank&quot;&gt;MediateView custom metadata extension&lt;/a&gt; that should handle most of these needs. I&apos;ll do my best to keep it up to date as I get feedback about it.

And finally, in the &quot;better late than never&quot; department, I&apos;ve uploaded the &lt;a href=&quot;http://slidesix.com/view/Swiz--Brian-Kotek--cfObjective&quot; target=&quot;_blank&quot;&gt;Swiz presentation I gave at cf.Objective() 2010&lt;/a&gt; to SlideSix. I&apos;ll also be speaking on Swiz at this year&apos;s &lt;a href=&quot;http://www.cfunited.com&quot; target=&quot;_blank&quot;&gt;CFUnited conference&lt;/a&gt;. If you&apos;re planning on going, I&apos;m happy to talk about Swiz into the wee hours of the morning!
				
				</description>
				
				
				<category>Flex</category>
				
				<category>Conferences</category>
				
				<category>Presentations</category>
				
				<category>Swiz</category>
				
				<pubDate>Wed, 19 May 2010 09:56:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2010/5/19/Swiz-10RC-Released-So-heres-an-updated-example-custom-ViewMediator-and-more</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Swiz Example Application Updated to Support Swiz 1.0 Beta</title>
				<link>http://www.briankotek.com/blog/index.cfm/2010/3/5/Swiz-Example-Application-Updated-to-Support-Swiz-10-Beta</link>
				<description>
				
				Update on 8/16/10: With the release of Swiz RC1, &lt;a href=&quot;http://www.briankotek.com/blog/index.cfm/2010/5/19/Swiz-10RC-Released-So-heres-an-updated-example-custom-ViewMediator-and-more&quot; target=&quot;_blank&quot;&gt;I released an updated version of this example application&lt;/a&gt;.

With the &lt;a href=&quot;http://swizframework.org/2010/03/swiz-1-0-0-beta-now-available/&quot; target=&quot;_blank&quot;&gt;release of the 1.0 Beta of the Swiz framework&lt;/a&gt;, I&apos;ve updated my &lt;a href=&quot;http://www.briankotek.com/blog/files/swiz_10_beta_example/Main.html&quot; id=&quot;l10.&quot; title=&quot;Swiz example application&quot;  target=&quot;_blank&quot;&gt;Swiz example application&lt;/a&gt; to the latest version. You can also &lt;a href=&quot;http://www.briankotek.com/blog/files/swiz_10_beta_example/srcview/&quot; id=&quot;wc4v&quot; title=&quot;view the source code&quot;  target=&quot;_blank&quot;&gt;view the source code&lt;/a&gt; if you like. I&apos;d like to point out a few things that I had to change from the example based on version 0.6.4:&lt;br&gt;
&lt;br&gt;&lt;ul&gt;&lt;li&gt;The instantiation of the framework has changed in order to support multiple instances of Swiz, primarily for Flex module support:&lt;br&gt;
&lt;code&gt;xml|
&lt;swiz:SwizConfig id=&quot;mySwizConfig&quot;
                 eventPackages=&quot;com.briankotek.swizdemo.event&quot;
                 viewPackages=&quot;com.briankotek.swizdemo.view&quot;
                 defaultFaultHandler=&quot;{genericFault}&quot; /&gt;

&lt;swiz:Swiz id=&quot;mySwiz&quot; beanProviders=&quot;{[Beans]}&quot; config=&quot;{mySwizConfig}&quot; /&gt;
&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The static methods on the Swiz class have been removed, due to the fact that there can now be multiple instances of Swiz. This means that instead of doing something like Swiz.dispatchEvent( event ), you now want to inject a dispatcher object into your non-view objects and dispatch events through it instead. The two main ways to do this are to inject the dispatcher in your BeanLoader/BeanProvider, or by having your class implement the IDispatcherAware interface, which will instruct Swiz to inject the dispatcher automatically.&lt;/li&gt;
&lt;li&gt;The [Autowire] metadata tag has been deprecated in favor of the more industry-standard [Inject]. [Autowire] will still work for now, but be aware that this may be removed in a future release.&lt;/li&gt;
&lt;li&gt;The use of the earlier CommandChain has changed to support more robust and extensible chains, as well as supporting internal Flex event-based chains on top of the existing support for chains that make server calls. For example:&lt;br&gt;
&lt;code&gt;js|
var chain : CommandChain = new CommandChain();&lt;br&gt;
chain.addMember( new AsyncChainStepCommand( delegate.deleteUser, [user], userDeleteHandler ) );&lt;br&gt;
chain.addMember( new AsyncChainStepCommand( delegate.deleteUserProfileImage, [user], userProfileImageDeleteHandler ) );&lt;br&gt;
chain.addEventListener( &quot;chainComplete&quot;, userDeleteCompleteHandler, false, 0, true );&lt;br&gt;
chain.start();
&lt;/code&gt;
&lt;/li&gt;&lt;/ul&gt;
Anyway, that&apos;s all for now, but I&apos;ll be posting more about the Swiz updates soon. If you&apos;re interested in seeing more about 1.0, have a look at &lt;a href=&quot;http://blog.foomonger.com/2010/02/26/swiz-signals-and-mediatesignal/&quot; target=&quot;_blank&quot;&gt;Sam Ahn&apos;s demo of Swiz using AS3Signals&lt;/a&gt;. A very cool use of the brand new custom metadata support now available in Swiz!
				
				</description>
				
				
				<category>Flex</category>
				
				<category>Swiz</category>
				
				<pubDate>Fri, 05 Mar 2010 08:59:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2010/3/5/Swiz-Example-Application-Updated-to-Support-Swiz-10-Beta</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Swiz 1.0 Beta is Live!</title>
				<link>http://www.briankotek.com/blog/index.cfm/2010/3/1/Swiz-10-Beta-is-Live</link>
				<description>
				
				This morning, the Swiz team released the &lt;a href=&quot;http://www.swizframework.org/files/swiz-v1.0.0-beta.swc&quot; target=&quot;_blank&quot;&gt;1.0 Beta of the Swiz Framework&lt;/a&gt;. You can view the extensive list of updates at the &lt;a href=&quot;http://swizframework.org/2010/03/swiz-1-0-0-beta-now-available/&quot; target=&quot;_blank&quot;&gt;Swiz web site&lt;/a&gt;. Have a look and try out the new features. We&apos;ll be doing a full update of the documentation as we prepare for the final release. I also have an updated version of my sample application about ready, and I will upload it and highlight the differences between 0.6.4 and 1.0. Stay tuned!
				
				</description>
				
				
				<category>Flex</category>
				
				<category>Swiz</category>
				
				<pubDate>Mon, 01 Mar 2010 11:29:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2010/3/1/Swiz-10-Beta-is-Live</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>My CFinNC Presentations at SlideSix</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/10/22/My-CFinNC-Presentations-at-SlideSix</link>
				<description>
				
				I&apos;ve uploaded my &lt;a href=&quot;http://www.cfinnc.com&quot; target=&quot;_blank&quot;&gt;CFinNC&lt;/a&gt; presentations to SlideSix for anyone who&apos;s interested:

&lt;a href=&quot;http://slidesix.com/view/Brian-Kotek--CFinNC--OO-Design-Principles-Final&quot; target=&quot;_blank&quot;&gt;Object-Oriented Design Principles&lt;/a&gt;

&lt;a href=&quot;http://slidesix.com/view/Swiz--Brian-Kotek--CFinNC&quot; target=&quot;_blank&quot;&gt;Introduction to Swiz&lt;/a&gt;

Overall, CFinNC was great. I actually had to work for a large chunk of the weekend so aside from presenting and mingling with folks later in the evening, I didn&apos;t get to attend many other sessions. That said, everything looked top-notch while I was there. The conference unfolded very smoothly and all of the attendees seemed very engaged. Hats off to Dan Wilson and the entire volunteer team for pulling this off! This conference definitely held its own against the other CF conferences I&apos;ve attended. It was very difficult to tell that it was completely free. Hopefully we can do it again next year!
				
				</description>
				
				
				<category>Development</category>
				
				<category>ColdFusion</category>
				
				<category>OOP CF</category>
				
				<category>Flex</category>
				
				<category>Conferences</category>
				
				<category>Presentations</category>
				
				<category>Swiz</category>
				
				<pubDate>Thu, 22 Oct 2009 12:02:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/10/22/My-CFinNC-Presentations-at-SlideSix</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>I&apos;m Speaking at the CFinNC Conference...See You There?</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/9/4/Im-Speaking-at-the-CFinNC-ConferenceSee-You-There</link>
				<description>
				
				Just a quick note that I&apos;ll be speaking at the &lt;a href=&quot;http://www.cfinnc.com/&quot; target=&quot;_blank&quot;&gt;CFinNC&lt;/a&gt; conference on October 17-18th here in Raleigh, NC. My topics are Object-oriented Design Principles and The Swiz Framework for Flex. 

The conference is FREE and the lineup is very impressive, so if you can attend, please register! And if you register, please actually show up! The danger with a free conference is that it&apos;s easy for folks to back out at the last minute, since they lose nothing. But for the organizers, it makes estimating actual attendance difficult. So if you sign up, please do your best to make it. :-)

I&apos;m looking forward to seeing some folks that I normally have to wait until MAX or next year&apos;s CFObjective or CFUnited conferences to see. And I hope to meet a lot of new people as well. See you in Raleigh!
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>OOP CF</category>
				
				<category>Flex</category>
				
				<category>Conferences</category>
				
				<category>Swiz</category>
				
				<pubDate>Fri, 04 Sep 2009 12:00:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/9/4/Im-Speaking-at-the-CFinNC-ConferenceSee-You-There</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Swiz Part 5: Simulating Server Calls with a mock AsyncToken</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/3/16/Swiz-Part-5-Simulating-Server-Calls-with-a-mock-AsyncToken</link>
				<description>
				
				In the last entry in this series on the Swiz framework, I discussed &lt;a
href=&quot;http://www.briankotek.com/blog/index.cfm/2009/2/9/Swiz-Part-4-Dynamic-Responders&quot;
target=&quot;_blank&quot;&gt;the use Dynamic Responders&lt;/a&gt; to make calls to the server as easy as possible. This entry is a short aside on how you can use some nice testing features that are built into Swiz to simulate calls to a server. As before, &lt;a
href=&quot;http://www.briankotek.com/examples/swizdemo_events/Main.html&quot;
target=&quot;_blank&quot;&gt;the current version of the application and its
source code&lt;/a&gt; is available.&lt;br&gt;
&lt;br&gt;
So far, we&apos;ve looked at how Swiz&apos;s inversion of control (IoC) features make managing dependencies in a Flex application dead simple. We&apos;ve dispatched events from the CentralDispatcher, and we&apos;ve executed service calls using our Delegate class. But what is actually happening at the Delegate level? Let&apos;s delve into this.&lt;br&gt;
&lt;br&gt;
You might have noticed that within my Controller, I&apos;m having Swiz wire in an object of type IUserDelegate:&lt;br&gt;

&lt;code&gt;js|
[Autowire]
public var delegate : IUserDelegate;
&lt;/code&gt;

Why am I specifying the type as an interface instead of an actual class name? Flexibility! One of the most basic tenants of object-oriented design is to &quot;design to interfaces&quot;. That doesn&apos;t necessarily mean you have to type everything as an interface. It just means you should keep your typing at the highest level of abstraction that you can. Ideally, that means typing things to interfaces or abstract classes.

Because I&apos;m typing the delegate to IUserDelegate, that means I can have Swiz autowire anything that implements the contract defined by the IUserDelegate interface. And that&apos;s exactly what I&apos;m doing. Here&apos;s the Beans.mxml file again:&lt;br&gt;

&lt;code&gt;xml|
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;BeanLoader 
	xmlns=&quot;org.swizframework.util.*&quot; 
	xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
	xmlns:controller=&quot;com.briankotek.swizdemo.controller.*&quot;
	xmlns:business=&quot;com.briankotek.swizdemo.delegate.*&quot;&gt;

	&lt;controller:UserController id=&quot;userController&quot; /&gt;
	&lt;business:MockUserDelegate id=&quot;userDelegate&quot; /&gt;

&lt;/BeanLoader&gt;
&lt;/code&gt;

You can see that the delegate is actually a MockUserDelegate. Here&apos;s the code for that class:&lt;br&gt;

&lt;code&gt;js|
package com.briankotek.swizdemo.delegate
{
	import com.briankotek.swizdemo.model.User;
	import mx.collections.ArrayCollection;
	import mx.rpc.AsyncToken;
	import org.swizframework.delegate.AbstractDelegate;
	import org.swizframework.util.TestUtil;

	public class MockUserDelegate extends AbstractDelegate implements IUserDelegate
	{
		
		// CONSTRUCTOR
		
		public function MockUserDelegate()
		{
			super();
		}
		
		// PUBLIC METHODS
		
		/**
		 * In a real application this would execute a server call to a remote object
		 */ 
		public function loadUsers() : AsyncToken
		{	
			return TestUtil.mockResult( buildMockUserCollection() );
		}
		
		/**
		 * In a real application this would execute a server call to a remote object
		 */ 
		public function saveUser( user : User ) : AsyncToken
		{
			if( !user.id )
			{
				user.id = Math.round( Math.random() * 100 );
			}
			return TestUtil.mockResult( user );
		}
		
		/**
		 * In a real application this would execute a server call to a remote object
		 */ 
		public function deleteUser( user : User ) : AsyncToken
		{
			return TestUtil.mockResult( user );
		}
		
		/**
		 * In a real application this might execute a call to a third party file server
		 */ 
		public function deleteUserProfileImage( user : User ) : AsyncToken
		{
			// Pretend that this deletes a file from a file server like Amazon S3.
			return TestUtil.mockResult( user ); 
		}

		// PRIVATE METHODS
		
		/**
		 * Build a fake collection of Users as a mock result.
		 */ 
		private function buildMockUserCollection() : ArrayCollection
		{
			var result : ArrayCollection = new ArrayCollection();
			
			var user1 : User = new User();
			user1.id = 1;
			user1.firstName = &quot;Tom&quot;;
			user1.lastName = &quot;Swift&quot;;
			result.addItem( user1 );
			
			var user2 : User = new User();
			user2.id = 2;
			user2.firstName = &quot;Bob&quot;;
			user2.lastName = &quot;Hope&quot;;
			result.addItem( user2 );
			
			var user3 : User = new User();
			user3.id = 3;
			user3.firstName = &quot;Alan&quot;;
			user3.lastName = &quot;Alda&quot;;
			result.addItem( user3 );
			
			var user4 : User = new User();
			user4.id = 4;
			user4.firstName = &quot;Roger&quot;;
			user4.lastName = &quot;York&quot;;
			result.addItem( user4 );
			
			return result;	
		}
	}
}
&lt;/code&gt;

As you can see, I&apos;m not actually making a call to a server. I&apos;m generating an ArrayCollection of &quot;fake&quot; User objects, and then using a handy method called mockResult() in the Swiz TestUtils class. This method generates an AsyncToken for you and adds your result to it. It will even let you simulate a delay, like a real server call would have.

In this way, you can easily test your Swiz application without needing the server side working. This not only makes examples like mine much easier to release, but it lets you unit test your applications, as well as do work on parts of the UI before the server-side code has been implemented yet.

I hope you can see the usefulness of this approach, the handy nature of Swiz&apos;s mockResult() method, and the ease with which Swiz lets you swap out implementations like this. I&apos;ll sign off for now, but in the next entry (which will come more quickly than this one did, I promise) we&apos;ll look at another great Swiz feature: Dynamic Event Mediators.
				
				</description>
				
				
				<category>Development</category>
				
				<category>Flex</category>
				
				<category>Swiz</category>
				
				<pubDate>Mon, 16 Mar 2009 13:16:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/3/16/Swiz-Part-5-Simulating-Server-Calls-with-a-mock-AsyncToken</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Swiz Part 4: Dynamic Responders</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/2/9/Swiz-Part-4-Dynamic-Responders</link>
				<description>
				
				In the last entry in this series on the Swiz framework, we looked at &lt;a href=&quot;http://www.briankotek.com/blog/index.cfm/2009/1/23/Using-Swiz-Part-3-Events&quot; target=&quot;_blank&quot;&gt;how the CentralDispatcher can make dealing with events a lot easier&lt;/a&gt;. Now I&apos;d like to take a look at how Swiz makes interacting with an application server just as simple. Once again, &lt;a href=&quot;http://www.briankotek.com/examples/swizdemo_events/Main.html&quot; target=&quot;_blank&quot;&gt;the current version of the application and it&apos;s source code&lt;/a&gt; is available.
				 [More]
				</description>
				
				
				<category>Flex</category>
				
				<category>Swiz</category>
				
				<pubDate>Mon, 09 Feb 2009 09:39:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/2/9/Swiz-Part-4-Dynamic-Responders</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Using Swiz Part 3: Events</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/1/23/Using-Swiz-Part-3-Events</link>
				<description>
				
				&lt;a href=&quot;http://www.briankotek.com/blog/index.cfm/2009/1/14/Using-Swiz-Part-2-Dependency-Injection&quot;&gt;In the last installment&lt;/a&gt;, we saw how Swiz can help you by resolving dependencies between your ActionScript classes and MXML components. But I left you with a very simple example, hardly more than a &quot;Hello World&quot;. In this entry, I&apos;d like to start digging into a more &quot;real world&quot; use of Swiz.

Based on some comments I&apos;ve gotten on and off the blog, I&apos;m uploading an interim version of the application with view source enabled. You can see it at &lt;a href=&quot;http://www.briankotek.com/examples/swizdemo_events/Main.html&quot; target=&quot;_blank&quot;&gt;http://www.briankotek.com/examples/swizdemo_events/Main.html&lt;/a&gt;. Keep in mind that in order to get it to a runnable state, the code contains a good number of things that I haven&apos;t talked about yet. Look around if you like, but for now don&apos;t pay too much attention to something if you aren&apos;t sure what it&apos;s doing yet. I&apos;ll get to it all, I promise! :-)

(A small note, right now there is an issue with the &quot;fake&quot; server calls that can cause the busy cursor to remain on screen. I believe this is a small issue with the test utility included in the Swiz library, and I&apos;m going to mention it to Chris. For now, just ignore it heh).

Judging by questions on the &lt;a href=&quot;http://groups.google.com/group/swiz-framework&quot; target=&quot;_blank&quot;&gt;Swiz discussion list&lt;/a&gt;, many people are a bit unsure of when things happen and when you are cleared to actually work with the beans that Swiz manages for you. If you run a Swiz application in debug mode, you should see some trace statements in the console that note several steps in the process. However, keep in mind that Swiz must create your objects first, and then autowire them. Which means that the dependent classes will not be available when your object is created, and references to dependent objects in your constructor will cause an error since the dependency hasn&apos;t been set yet.

The same is true for views, in that view components are not autowired until they are added to the stage, which is occurs near the end of the component lifecycle. It happens after creationComplete, which means you are not safe referencing dependencies in that event handler. Further, because of the fact that Flex events like creationComplete execute in sequence from the innermost child up through the display list hierarchy to the root container (the Stage), you must exercise even more care. (And that is a general issue for Flex development, not really specific to Swiz).

I&apos;ve found that the easiest way to deal with issues like these is to minimize reliance on creationComplete, as well as minimizing situations where you try to pass data into a visual component from a parent. For example, consider:

&lt;code&gt;
&lt;view:UserContainer id=&quot;userContainer&quot; width=&quot;100%&quot; height=&quot;100%&quot; users=&quot;{userController.users}&quot; /&gt;
&lt;/code&gt; 

It might look OK on the surface, but we can run into issues if the UserContainer component does something like this in it&apos;s creationComplete handler:

&lt;code&gt;js|
private function creationCompleteHandler() : void
{
    if( users.length &gt; 0 )
    {
        // do something
    }
}
&lt;/code&gt; 

You see the problem? When UserContainer&apos;s creationCompleteHandler runs, it&apos;s parent hasn&apos;t had the controller autowired into it yet! Which means the reference to users in the UserContainer will be null. In fact, the parent hasn&apos;t even had the controller autowired into it yet. As an aside, some of the most difficult initial mental obstacles I faced when starting with Flex was this issue of creation timing. It can get pretty nasty when you have several levels of components, each depending on something provided by their parent. But I digress.

Basically I&apos;ve found it best to let the application set itself up and THEN dispatch an event that begins populating things with data. And this is where I can also introduce the Swiz CentralDispatcher. In my user manager application, I need SOMETHING to set off processing that gets the list of users and displays it in the data grid. I used a simple approach like this in my Main.mxml file:

&lt;code&gt;js|
private function applicationCompleteHandler( event : Event ) : void
{
	Swiz.dispatchEvent( new Event( UserController.APPLICATION_LOAD_REQUESTED ) );
}
&lt;/code&gt;

So once this event fires, that means all of the child components have been created, added to the stage, and had any Swiz beans autowired in. At this point, I know the application is in a state where everything is ready to go.

Right away, you may notice the first advantage of Swiz&apos;s event dispatching mechanism: it doesn&apos;t require custom or framework-specific Events. Frameworks like Cairngorm demand that you use their &quot;special&quot; Event objects. Not so with Flex. You can use custom Event types if you like, or you can use standard Flex events. It&apos;s one less framework dependency.

Note that Swiz makes using it&apos;s event dispatching mechanism as simple as possible by providing static methods on the Swiz class to handle listening for and dispatching events. It&apos;s just one more nice convenience that Chris had the foresight to add.

The benefit of using a central dispatcher like the one Swiz provides is to get around an issue with the way Flex normally dispatches events: they only &quot;bubble UP&quot; the component hierarchy. There&apos;s no easy way to get CHILD components to respond to an event that is dispatched by a parent. By dispatching events through the central dispatcher, any class can listen for events of interest, regardless of where they sit in the hierarchy.

If you look at the controller code that handles this APPLICATION_LOAD_REQUESTED event, it&apos;s a standard event listener and corresponding handler. The only difference of note is that the listener is configured on the Swiz central dispatcher:

&lt;code&gt;js|
public function UserController()
{
	super();
	users = new UserListCollection();
	Swiz.addEventListener( APPLICATION_LOAD_REQUESTED, loadUsers );
}

public function loadUsers( event : Event ) : void
{
	executeServiceCall( delegate.loadUsers(), userLoadHandler );
}
&lt;/code&gt;

Ignore the &quot;executeServiceCall()&quot; method for now, we&apos;ll get to that in the next entry. The point is: from here, my application kicks off the process of getting the user list and then providing it to the view. If you look at the attached code, you can see that the Swiz central dispatcher is also used to move data into the view.

That&apos;s all for now. In the next entry, I&apos;ll look at how Swiz makes getting data from the server just as easy.
				
				</description>
				
				
				<category>Development</category>
				
				<category>Flex</category>
				
				<category>Swiz</category>
				
				<pubDate>Fri, 23 Jan 2009 09:42:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/1/23/Using-Swiz-Part-3-Events</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Using Swiz Part 2: Dependency Injection</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/1/14/Using-Swiz-Part-2-Dependency-Injection</link>
				<description>
				
				In my &lt;a href=&quot;http://www.briankotek.com/blog/index.cfm/2009/1/8/Using-Swiz-Part-1-Initial-Setup&quot; target=&quot;_blank&quot;&gt;last entry&lt;/a&gt;, I showed how to get a Flex application up and running using the &lt;a href=&quot;http://code.google.com/p/swizframework/&quot; target=&quot;_blank&quot;&gt;Swiz framework&lt;/a&gt;. In this post, I&apos;m going to take a look at what is probably Swiz&apos;s killer feature: dependency injection.

Folks familiar with Spring or ColdSpring will recognize the term, but in case you don&apos;t, let me quote from &lt;a href=&quot;http://en.wikipedia.org/wiki/Dependency_injection&quot; target=&quot;_blank&quot;&gt;Wikipedia&lt;/a&gt;:

&lt;blockquote&gt;
Conventionally, if an object needs to gain access to a particular service, the object takes responsibility to get hold of that service: either it holds a direct reference to the location of that service, or it goes to a known service locator and requests that it be passed back a reference to an implementation of a specified type of service. By contrast, using dependency injection, the object simply provides a property that can hold a reference to that type of service; and when the object is created a reference to an implementation of that type of service will automatically be injected into that property by an external mechanism.
&lt;/blockquote&gt;

If that&apos;s a little too technical for anyone, I&apos;ll translate a bit. The idea is to use some external process to look at the dependencies between your objects, create them in the proper order, and then supply the necessary objects to each other. 

&lt;more /&gt;

Consider how you might be creating objects right now. You could be doing something like this in your Main.mxml file or some kind of configuration object:

&lt;code&gt;js|
var xmlUtils = new XMLUtils();
var contentDelegate = new ContentDelegate();
contentDelegate.xmlUtils = xmlUtils;
var securityController = new SecurityController();
securityController.xmlUtils = xmlUtils;
var contentController = new ContentController();
contentController.securityController = securityController;
contentController.contentDelegate = contentDelegate;
&lt;/code&gt;

So ContentController needs instances of SecurityController and ContentDelegate, which in turn both need an instance of XMLUtils. Kind of nasty, and we&apos;re only dealing with four objects. Now think about what that would look like for 40 objects. Or 400. Yikes.

Wouldn&apos;t something like this be nicer? Imagine this within the ContentController:

&lt;code&gt;js|
[Autowire]
public var securityController : SecurityController;

[Autowire]
public var contentDelegate : ContentDelegate;
&lt;/code&gt;

This is exactly what Swiz will do. Once you initialize the framework and supply a set of bean definitions (which I did in my last blog entry), Swiz will automatically create those components and resolve all of their dependencies. Which, if you think about it, is pretty killer. But it doesn&apos;t stop there. In addition to autowiring Singleton components like controllers and delegates, it will also autowire your views! Yes, it&apos;s true. If you have a view containing properties with [Autowire] metadata, Swiz will inject the proper beans into your view as soon as it is added to the stage. Which sweeps away all sorts of issues (or at least issues that I had run into before) related to the creation order of display objects.

A few additional notes about autowiring. In the examples above, I&apos;m using what is called &quot;autowire by type&quot;. This means that Swiz looks at the property&apos;s type and then looks for a bean that it is managing with the same type. It even works with interfaces and supertypes, which is very useful. Autowire by type is fine for most situations, but if you can&apos;t rely on the type alone (such as having Swiz manage multiple different beans of the same type), you can also specify the bean ID if you need to:

&lt;code&gt;js|
[Autowire( bean=&quot;userController&quot; )]
public var userController : UserController;
&lt;/code&gt;

Another handy feature is that you can autowire properties that are declared using implicit setters as well. This means that you can execute additional logic when the bean is autowired:

&lt;code&gt;js|
[Autowire]
public function set userController( userController : UserController ) : void
{
	_userController = userController;
	// Run some additional code after the userController is set.
}
public function get userController() : UserController
{
	return _userController;
}
private var _userController : UserController;
&lt;/code&gt;

There are a few other cool features related to autowiring and the process Swiz goes through to resolve the dependencies and create the beans, but I don&apos;t want to veer too far off into the low level details. Let&apos;s return to the little user manager application that I prototyped in the previous entry. With these ideas about autowiring in mind, lets see how we can apply them to this application. I don&apos;t have much in the way of dependencies because there are only a small number of classes, but my Beans.mxml file looks like this:

&lt;code&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;BeanLoader 
	xmlns=&quot;org.swizframework.util.*&quot; 
	xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
	xmlns:controller=&quot;com.briankotek.swizdemo.controller.*&quot;
	xmlns:business=&quot;com.briankotek.swizdemo.delegate.*&quot;
	&gt;

	&lt;controller:UserController id=&quot;userController&quot; /&gt;
	&lt;business:MockUserDelegate id=&quot;userDelegate&quot; /&gt;

&lt;/BeanLoader&gt;
&lt;/code&gt;

So Swiz is managing two beans for me, a User controller and a User delegate. I want the delegate wired into the controller, so my controller will start off like:

&lt;code&gt;js|
package com.briankotek.swizdemo.controller
{
	import com.briankotek.swizdemo.delegate.IUserDelegate;
	import org.swizframework.controller.AbstractController;

	public class UserController extends AbstractController
	{
	// PUBLIC PROPERTIES
	
	[Autowire]
	public var delegate : IUserDelegate;
	}
}
&lt;/code&gt;

I&apos;m specifying the delegate&apos;s type as an interface (IUserDelegate) so that I can swap implementations of the delegate if I want to, such as swapping the MockUserDelegate for a real UserDelegate later on. As long as they both implement the IUserDelegate interface, nothing outside of Swiz needs to know which one is actually being used. We&apos;ll look at this delegate in detail in an upcoming post.

For now, let&apos;s just see this work. My Main.mxml file to test that the autowiring is working is:

&lt;code&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application 
	xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; 
	layout=&quot;absolute&quot;
	preinitialize=&quot;preinitializeHandler( event )&quot;
	&gt;
	
	&lt;mx:Script&gt;
	&lt;![CDATA[
	import com.briankotek.swizdemo.config.Beans;
	import com.briankotek.swizdemo.controller.UserController;
	import org.swizframework.Swiz;
	
	[Autowire]
	[Bindable]
	public var cont : UserController;

	private function preinitializeHandler( event : Event ) : void
	{
	Swiz.loadBeans( [Beans] );
	}
	
	]]&gt;
	&lt;/mx:Script&gt;
	
	&lt;mx:Text id=&quot;testing&quot; text=&quot;Is the UserController set, and was the deleage wired into it? {cont.delegate != null}&quot; /&gt;
	
&lt;/mx:Application&gt;
&lt;/code&gt;

Which reveals that the controller was indeed wired into my view correctly, as well as confirming that the delegate was wired into the controller correctly. And this was all done in an impressively small amount of code. Hopefully this gets your mind turning about the potential of dependency injection. Remember that this is a deliberately small example, but you can probably see how much of a benefit this would be in larger applications.

That&apos;s all for today, but in the next entry, we&apos;ll move away from just running a simple test in the Main.mxml. On the whole, Flex apps don&apos;t really work like this. Flex is an event-driven framework, with code dispatching events to trigger the execution of additional logic. We&apos;ll see how Swiz facilitates this through it&apos;s central event dispatcher.
				
				</description>
				
				
				<category>Development</category>
				
				<category>Flex</category>
				
				<category>Swiz</category>
				
				<pubDate>Wed, 14 Jan 2009 11:15:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/1/14/Using-Swiz-Part-2-Dependency-Injection</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Using Swiz Part 1: Initial Setup</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/1/8/Using-Swiz-Part-1-Initial-Setup</link>
				<description>
				
				To begin this series on Swiz, I whipped up a couple of mockups using Balsamiq to show what the end result should be. It&apos;s going to be a pretty simple user manager interface. Let&apos;s have a quick look at those images and then we&apos;ll move on to setting up an application shell for this using Swiz.
				 [More]
				</description>
				
				
				<category>Development</category>
				
				<category>Flex</category>
				
				<category>Swiz</category>
				
				<pubDate>Thu, 08 Jan 2009 09:53:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/1/8/Using-Swiz-Part-1-Initial-Setup</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>A New Series on Understanding and Using the Swiz Framework for Flex</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/1/5/A-New-Series-on-Understanding-and-Using-the-Swiz-Framework-for-Flex</link>
				<description>
				
				As part of my commitment to blog more often in 2009, I&apos;m starting an ongoing series on the &lt;a href=&quot;http://code.google.com/p/swizframework/&quot; target=&quot;_blank&quot;&gt;Swiz framework for Flex&lt;/a&gt;. If you aren&apos;t aware, Swiz is the brianchild of Chris Scott, and may CF&apos;ers will recognize him from this work on the ColdSpring framework. Being the brilliant guy that he is, he&apos;s taken many of the principles of Spring and ColdSpring and applied them to Flex development. The result is Swiz, and after doing work with Cairngorm, Swiz is like being paroled! It feels pretty nice to do things simply with Swiz that would have required large amounts of boilerplate code in Cairngorm.

At &lt;a href=&quot;http://www.broadchoice.com&quot; target=&quot;_blank&quot;&gt;Broadchoice&lt;/a&gt;, we chose Swiz as the framework to underpin our Workspace application. As a result, I&apos;ve had a good amount of time to get familiar with Swiz and try out some of it&apos;s bleeding-edge features. What I&apos;d like to do is share what I&apos;ve learned about it, with two main goals: To explain how it is useful to folks not familiar with it (or even with Flex for that matter). And second, to try and get some discussion going among those already using Swiz to see if I can learn more from them, and vice versa.

I&apos;ve chosen to examine and work through a fairly simple (though non-trivial) Flex application that uses Swiz. Over the coming days and weeks I&apos;ll be blogging about various pieces of the application and what Swiz is doing. I figure it will end up being about 7 or 8 blog entries, but we&apos;ll see how it goes and what sort of comments and response I get.

Just to create a starting point to work up from, here are some of the topics I plan to talk about. Each of these is incorporated in the sample application I&apos;m building, so we&apos;ll do more than simply talk about these, we&apos;ll put them to use.

&lt;ul&gt;
&lt;li&gt;Getting a Swiz application running&lt;/li&gt;
&lt;li&gt;Swiz dependency injection and autowiring&lt;/li&gt;
&lt;li&gt;Using the Swiz Central Dispatcher for events&lt;/li&gt;
&lt;li&gt;Dynamic Responders&lt;/li&gt;
&lt;li&gt;Using the MockAsyncToken to simulate remote server requests&lt;/li&gt;
&lt;li&gt;Dynamic Mediators&lt;/li&gt;
&lt;li&gt;Dynamic Commands&lt;/li&gt;
&lt;li&gt;The Fluint unit testing framework for Flex&lt;/li&gt;
&lt;li&gt;Integrating Swiz into Fluint to ease testing&lt;/li&gt;
&lt;/ul&gt;

I have a few other ideas for topics that I may throw in or add as tangents, but let&apos;s see how this initial roadmap goes. I&apos;ll be working on the app as we go, so I&apos;ll primarily be posting code in the blog entries, and then at the end I&apos;ll push a finalized zip file of the application for folks to download and play with. The first entry will up in the next day or so. What do you folks think? Anyone out there ready to dig into Swiz with me?
				
				</description>
				
				
				<category>Development</category>
				
				<category>Flex</category>
				
				<category>Swiz</category>
				
				<pubDate>Mon, 05 Jan 2009 09:56:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/1/5/A-New-Series-on-Understanding-and-Using-the-Swiz-Framework-for-Flex</guid>
				
				
			</item>
			
		 	
			</channel></rss>