没有合适的资源?快使用搜索试试~ 我知道了~
首页parsley2.4英文开发手册
parsley2.4英文开发手册

parsley2.4英文开发手册 parsley2.4英文开发手册 parsley2.4英文开发手册 parsley2.4英文开发手册 parsley2.4英文开发手册
资源详情
资源评论
资源推荐

1 Overview
Parsley is an Application Framework for Flex and Flash Applications built upon an IOC Container and Messaging
Framework that can be used to create highly decoupled architectures. It allows you to configure objects to be managed
by the container with Metadata, MXML, XML or ActionScript and is easily extensible.
While many other Application Frameworks for the Flash Platform are either a pure Flex Framework that cannot be used
without the Flex SDK or are a classic Flash Framework without any deeper integration with Flex, Parsley is both. The
core of the framework (the IOC Container and the Messaging Subsystem) does not depend on the Flex SDK at all, but
there are several additional modules that are specifically designed for Flex, providing support for MXML Configuration,
View Wiring and Flex Modules.
1.1 Features List
This section gives a quick overview over the available features linking to the other chapters of the manual where
appropiate. There is also a 2 Getting Started chapter containing a few sample use cases for the impatient.
IOC Container
Parsley is a classic IOC Container. It provides support for Dependency Injection, Object Lifecycle Management and
Messaging. The key differentiator is the scope of the framework: While still being as easy to use as many smaller IOC
frameworks for simple applications, it also provides many features which are essential for building large, complex and
modular applications, like support for Flex Modules, Object Disposal or numerous extension points.
Dependency Injection
The core feature of any IOC Container. Now with Parsley 2 dependencies can be conveniently declared using AS3
Metadata Tags ([Inject]) on properties, methods or constructors or alternatively with MXML or XML. See
4
Dependency
Injection for details.
Messaging
Parsley contains a Messaging Framework that allows for objects to send and receive messages in a fully decoupled way.
You can declare events on sending objects with the [ManagedEvents] tags, so that they will be routed through Parsley
to all registered handlers. The receiving objects can declare interest in particular message types with several metadata
tags like [MessageHandler]. Message selection happens based on the type (class) of the message and optionally based
on additional selectors like event type, instead of being purely String based like regular event handlers. This eases
development of large applications where you don't have to care for event type constants being unique for the whole
system. See 5
Messaging for
details.
Advanced IOC Container Features
6.5
Context
Lifecycle: Objects can have methods marked with [PostConstruct] (which will be invoked after the
object has been instantiated and configured) or [PreDestroy] which will be invoked when the container gets destroyed.
For modular applications it's essential that you can create dynamically loaded sub-contexts and be able to dispose the
whole module when it's no longer needed by the application.
6.2 Asynchronous Object Initialization: Configuration option for asynchronously initializing objects (e.g. objects that
need to load data before they can operate). In this case the container will defer the initialization of other objects until
those configured to be asynchronous are ready.
Flex View Wiring
This is a special integration module for Flex and solves the problem that you usually wouldn't want to declare Flex
Components in IOC Container configuration files, but instead inside your MXML view hierarchy like always. Parsley 2
now allows to connect these components to the IOC Container on-the-fly when they are added to the stage. See 7 Flex
Component Wiring for details.
Support for Flex Modules

Being also a special integration module for Flex it allows to associate a set of configuration classes or files with a Flex
Module, containing services, actions, mediators and so on, which are only needed for a particular context. The whole
sub-context gets automatically destroyed, disposing all objects configured for the module, when the Flex Module gets
unloaded. See 8 Using Flex Modules for details.
Localization
Allows to bind properties to resources with the [ResourceBinding] tag. Integrates with the Flex ResourceManager for
Flex Applications and contains its own Localization Module for Flash Applications. See 10
Localization for details.
Extensibility
Parsley can serve as the base for building higher-level frameworks on top of. Or you may just want to create some
additional configuration tags for use cases which are frequent for a particular application. Parsley is easy to extend. A
single implementation of an extension interface can be used to create a custom configuration tag that can be used as a
Metadata, MXML or XML tag. See 11
Extending the Framework and 6.1
Using Factories for details.
1.2 Parsley and Spicelib Module SWCs
Parsley and the underlying Spicelib are very modular, so you are able to only select the SWCs actually required for your
application. The release folder in the download contains SWCs for Parsley and Spicelib which combine all the modules
into a single large SWC (for both frameworks one SWC for Flex and one for Flash).
Alternatively the module folder contains smaller SWCs only containing a single framework module which can be
combined to add only the feature set required by your application to the classpath. To use these smaller module SWCs
it's essential to know the dependencies and the content of each SWC.
The following diagram shows the dependencies between the various SWCs. The names correspond to the names of the
SWCs minus version number and suffix. Several optional dependencies were left out to keep the diagram clear. Most of
them are obvious (e.g. several modules include custom XML configuration tags and in case you use those the module
will also depend on parsley-xml).

The following table summarizes the content for each of these SWCs:
spicelib-core Core utilities, errors and events.
spicelib-
reflect
The Spicelib Reflection API. See 17
Reflection for details.
spicelib-xml The XML-to-Object Mapper. See 18 XML to Object Mapper for details.
spicelib-task The Task Framework for asynchronous operations. See 19
The Task Framework for details.
spicelib-
flash
The Flash Logging Framework. See 20 Logging for Flash Applications for details.
parsley-core
The core IOC Container - Dependency Injection, Messaging, Configuration with Metadata or
ActionScript.
parsley-flex
Flex Integration Features: 3.2 MXML Configuration, 7 Flex Component Wiring, 8 Using Flex
Modules.
parsley-xml Support for configuration with XML files. See 3.3
XML Configuration Files for details.
parsley-flash
Flash Integration Features: 10.3
Localized Flash Applications, 13.2
Logging Configuration
for Flash.
parsley-
pimento
Configuration Tags for Pimento and Cinnamon. See 12.2
Pimento Data Services and
12.3
Cinnamon Remoting.
1.3 Other resources

In addition to the material presented in this manual there are also some articles and sample applications available
which have been created by other users. If you have created something that you want to see listed here just post a link
in the Forum.
Building a Flex Application with the Parsley Framework: Article and Sample Application created by Christophe
Coenraets. The sample is a small Contact Management application. It can be run with a mock service implementation
or with BlazeDS.
Inversion of Control and Dependency Injection in Flex using the Parsley Application Framework: Two-part
article by Joel Hooks.
The Trend Towards Inversion-of-Control Frameworks in Flex: Article written by Tom Sugden. Not focused
solely on Parsley but nevertheless and interesting read.
Basic Flex Example and Basic Flash Sample: Two basic samples created by Laurent Sitronnier. Demonstrates the
use of Parsley in Flex and Flash Applications side-by-side.

2 Getting Started
This chapter gives a very quick introduction on how to build an application with Parsley, linking to other parts of the
manual for more detailed descriptions. Most of the explanations apply in the same way to building Flex or Flash
Applications. Examples that only apply for Flex development will be pointed out accordingly.
2.1 Adding the Framework SWCs
To start working with Parsley you need to add several of its SWCs to your classpath first. Which ones you'll need
depends on the feature set you'll be using and whether you'll be building a Flex or Flash Application.
The quickest way to get started is to add the SWCs that contain the whole framework. You'll find them in the release
folder of the download Zip.
Required SWCs for Flex Applications
parsley-complete-flex-${version}.swc
spicelib-complete-flex-${version}.swc
Required SWCs for Flash Applications
parsley-complete-flash-${version}.swc
spicelib-complete-flash-${version}.swc
Selecting individual Framework SWCs
If you want to explicitly select the framework modules that you are actually using to keep your classpatch clean, you
can alternatively chose several of the module SWCs contained in the modules folder within the release folder. For that
you'd need to know the content and the dependencies for those SWCs, which is described in 1.2 Parsley and Spicelib
Module SWCs.
2.2 Defining Object Dependencies
This is probably the most frequently used feature of Parsley. Defining dependencies is a lot more convenient since
Parsley 2 where we introduced configuration with Metadata or MXML in addition to XML files.
Using the [Inject] metadata tag
You can use the tag on properties:
Or you can use it on methods to declare multiple dependencies at once:
The nice thing in the example above is that Parsley will also reflect on the parameter types and treat optional
parameters as optional dependencies. So in this example the container will throw an Error if the LoginService is
missing, but silently skip the CartService if it is not present in the container.
Finally you can also use a similar tag ([InjectConstructor]) on the class declaration for constructor injection (as the
[Inject]
public var loginService:LoginService;
[Inject]
public function set loginService (service:LoginService) : void {
[Inject]
public function init (loginService:LoginService, cartService:CartService = null) : void {
剩余113页未读,继续阅读






安全验证
文档复制为VIP权益,开通VIP直接复制

评论2