Flex Development with the Swiz Framework
The Adobe Flex and AIR community continues to mirror many of the trends of the early Java community, with numerous individuals offering frameworks that aim to simplify or improve Flex development. This post reviews the Swiz Framework, which models itself after many of the principles found in the SpringFramework for Java. The Swiz framework was developed by Chris Scott, and is offered under the Apache License 2.0.
At his core, Swiz is a simple inversion of control framework. Using an IoC framework, the components of your application (for example, Views) don’t instantiate or even look up their dependencies (the objects they work with). The framework injects those dependencies when the components are created (hence the term “Dependency Injection” also used to describe this approach). The result is looser coupling and more reusable components. The components managed by the Swiz IoC framework are called beans.
In Christophe's sample application he shows the Spring like syntax for injection:
Swiz uses the [Autowire] custom metadata to inject beans into other beans and views.
In inSync, the contactService RemoteObject is injected into ContactController.as as follows:
1 2 [Autowire(bean="contactService")] public var contactService:RemoteObject;
… and contactController is injected in the Views. For example, in ContactForm.mxml:
1 2 [Autowire(bean="contactController")] public var controller:IContactController;
In a recent review of the Swiz Framework, Tony Hillerson discussed the Autowiring features:
In case you didn’t notice, this Autowire thing is sweet. We don’t have to worry about where this model comes from. We don’t have to think about if it’s a Singleton or not. All we know is that we want a model, and the framework will make sure we have one when we need it. One note of caution: the property has to be marked public or Swiz won’t be able to assign to it.
Both Tony and Christophe concluded that Swiz is a framework that is easy to use, Christophe saying:
Swiz was easy and enjoyable to work with. It is also non intrusive and definitely introduces some interesting ideas.
To learn more about Swiz and its features check out the project tutorial.
New Swiz Framework 1.0
This is a link to old Swiz 0.6 . Check out the Tutorial for new Swiz Framework 1.0
Edmund Jorgensen Nov 27, 2014
Lisa Adkins and Michael Spayd Nov 27, 2014