flexcoders  

Re: [flexcoders] Prana: IoC container for AS3

Christophe Herreman
Fri, 20 Apr 2007 23:55:13 -0700

Hi Brian,

there might indeed be a difference between Flex projects that use Flex 
Data Services vs. compiled Flex/Flash/AS3 projects. The FDS projects 
have a huge advantage of having the code compiled on the server.

For instance to change Cairngorm's ServiceLocator and define where to 
find let's say a RemoteObject's endpoint, you could simply replace the 
services.mxml. In a compiled app, you'd have to recompile it after 
changing the remote object's details. You could of course write custom 
configuration code that reads an xml or a text file and defines the 
remote object's details that way, but if you need to do that for several 
objects in your application, your code becomes cluttered with 
configuration code. By using an IoC applicationcontext, you don't need 
to write custom code for parsing and assigning the properties of an 
object, because the container does that for you.

But also with FDS I can see some advantages in using IoC. I will again 
refer to Cairngorm where BusinessDelegates typically lookup a service in 
the ServiceLocator and commands instantiate a business delegate. You now 
have code like this:

this.service = ServiceLocator.getInstance().getRemoteObject( 
"productService" ); (in the business delegate)
and
var delegate : ProductDelegate = new ProductDelegate( this ); (in the 
command)

But what happens if we go from using remoting to using webservices or 
httpservices? We would have to change the businessdelegate and possibly 
also the code of our commands to read the data returned by the remote 
call, the webservice of the httpservice. It would be better if we had an 
accessor for a businessdelegate on our command and an accessor for a 
service on our businessdelegates. If everything is typed to an interface 
the code would not be aware of any implementation details and we would 
be able to leave that up to the application context. If we would work 
out this case in a Cairngorm app, it would most likely require some 
changes in the framework itself. I'll try to work out an example in the 
coming weeks as a proof of concept.

Any thoughts?

best regards,
Christophe

Brian Lesser wrote:
>
> Hi Carlos, et al,
>
> I have a question regarding the need for an ioc container for Flex as
> opposed to a pure AS3 or Flash project. Flex already provides a
> hierarchy of containers that contain controls and service proxies. The
> containers are usually responsible for setting the dependencies between
> controls and proxies. Setting dependencies can be done with databinding,
> simple assignment, or by setting up listeners. This is a very different
> situation from what a Java developer faces without an IOC container when
> writing servlets or JSP pages. In fact in Flex the built in visual state
> mechanism means we can set up dependencies and tear them down when
> states are entered and left. So, here's my question: what would an IOC
> container add that Flex doesn't provide and how would it improve our
> work or what we could do? Are you primarily thinking about aspects?
>
> Yours truly,
> -Brian
>
> Carlos Rovira wrote:
>
> > Looks very promising :)
> >
> > Great!
> >
> > C.
> >
> > PD:mmm... no body else seems to be interested in this proyect? people
> > know about the benefits of a IoC container?
> >
> > 19 Apr 2007 04:03:30 -0700, Christophe Herreman < [EMAIL PROTECTED] com
> > <[EMAIL PROTECTED] <mailto:lists%40herrodius.com>>>:
> >
> > Hi Carlos,
> >
> > I don't really have an official roadmap, but here are some of the
> > things
> > I'd like to achieve:
> > - IoC container
> > - IoC utils for frameworks like Cairngorm and ARP
> > - AOP framework
> > - Mock Objects for FlexUnit
> > - Reflection API
> > - general utilities
> >
> > Reading this myself, it looks very optimistic ;-) but the
> > motivation is
> > there so, what the heck.
> >
> > A first version of the Reflection API has just been added to the SVN
> > repo BTW.
> >
> > regards,
> > Christophe
> >
>
> -- 
> __________________________________________________________
> Brian Lesser
> Assistant Director, Application Development and Integration
> Computing and Communications Services
> Ryerson University
> 350 Victoria St.
> Toronto, Ontario Phone: (416) 979-5000 ext. 6835
> M5B 2K3 Fax: (416) 979-5220
> Office: POD?? E-mail: [EMAIL PROTECTED] <mailto:blesser%40ryerson.ca>
> (Enter through LB99) Web: http://www.ryerson.ca/~blesser 
> <http://www.ryerson.ca/%7Eblesser>
> __________________________________________________________
>
>