I’m rolling out a large project, and I wanted to utilize dynamic modules for scalability.
For those who aren’t familiar will modules, basically, there a great way to encapsulate “pieces” of your application. A trivial example would be a small ‘shell application’ that once the user logs in, loaded the appropriate use-case module. If your working in a team environment modules make for an easy project divide-and-conquer approach.
I’ve been using the PureMVC framework lately and figured adding support for dynamic modules wouldn’t be too difficult as Cliff and the gang have already been hard at working getting the framework changes in place to make this possible (replacing singletons with multitons etc).
Well after some working laying this out, I’m glad to say I’ve got it working. Check out this sample app Dynamic Mortgage Demo.
The demo allows the user to get loan quotes from [fictional] banks. The demo allows the user to dynamically load / unload bank “modules.”
The application and modules are very well encapsulated. Here’s whats required from each party…
Application:
Must compile with…
A reference to any interfaces the modules loaded at runtime implement (ILoadableModule in our case).
A reference to any subclasses of mx:Module the modules are using (PureMVCLoadableModule in our case). This is only necessary if your subclassing mx:Module.
That’s it.
Here’s the integration point on the modules end…
The modules facade implements an “InitializeMapping” function which maps application notification names to local (module) notification names [inbound mapping]. The function also defines module notification name to application notification name [outbound] mappings.
Here’s an example
override public function initializeMappings():void
{
outboundMappings:Array = new Array();
outboundMappings[QUOTE_GENERATED] = EventNames.LOAN_QUOTE_READY;
inboundMappings = new Array();
inboundMappings[EventNames.REQUEST_FOR_LOAN] = QUOTE_REQUESTED;
}
And thats the extent of what our application and modules know of each other. The rest of the ‘work’ is done automatically by a few interfaces / subclasses I wrote on top of PureMVC to make this possible. (i.e. your modules facade subclasses ModuleFacadeBase etc). No framework changes we’re required just some subclassing here and there.
Jan
May 20, 2008 at 6:00 am
Your demo is missing com.dl.modules.core submap, please send it to me also
admin
May 20, 2008 at 10:51 am
Jan,
All set, the dl.modules source is now included.
Josh
Kevin
May 23, 2008 at 11:59 am
The classes ModuleSelectorMediator.as, ModuleListingProxy.as, PureMVCModule.as, PureMVCModuleLoader.as, and ModuleManagementProxy.as all use Flex libraries. How would you recommend getting this setup to be pure AS3? Any suggestions? Thanks for sharing, I like what I see so far.
admin
May 23, 2008 at 7:47 pm
Kevin,
PureMVCModuleLoader.as would be the key file to port. The rest should fall in place after that. If I have some time tonight I’ll see if I can write a quick ‘pure AS3′ port.
FYI – Basically you’ll use flash’s Loader class
flex2colombia
September 3, 2008 at 2:50 pm
Congratulations!
great Work…
I am using it in a new project…
derstepppenwolf
September 3, 2008 at 5:40 pm
I have a Little question…
How do you debug modules with your framework?
At this moment in my debug environment the module is never loaded…
but in the web environment works fine..
Joshua
September 9, 2008 at 10:59 am
I’d place some breakpoints on the module load event’s to see where the loading is failing. Feel free to email more details
Shweatha
February 3, 2009 at 1:30 pm
Hi,
I am pretty new to flex environment. Can you please provide me the source code for the demo you have provided.
Thanks.
Joshua
February 12, 2009 at 7:08 pm
Shweatha,
Simply right click to view source
Lorenzo
March 3, 2009 at 5:42 am
Hi,
very nice post…
is it possible to achieve inter-modules communication? How to?
thanks a lot
Regards Lorenzo
Joshua
March 4, 2009 at 9:09 am
Lorenzo,
I commented on your other question over at http://www.joshuaostrom.com/2008/06/12/puremvc-pipes/ . Please see that response for reference.
Josh
Eric Taylor
March 2, 2010 at 9:22 pm
Mr. Ostrom,
First, I should say, your examples, articles, and demos are fantastic, ideal for someone starting out in Flex and PureMVC. Thank you for your work.
I’m a certified .NET developer who is moving to Flex [and PureMVC MultiCore]. I’m having trouble setting up modules when they reside in separate Flex Library Projects.
I’ve structured my application so that the application itself resides in a Flex Project, the modules in a Flex Library Project, and ‘common’ in a Flex Library Project. But I’m having trouble getting the modules and the application to recognize ‘common’. I’ve been posting in the Architecture forum at PureMVC (which is where I encountered your name). Cliff has been most helpful, but his most recent reply left me confused. (You can see my posts under the username ‘estaylorco’.
Could you offer some pointers on how to handle cross-project references? Cliff suggests that what I’m doing (which is what you did) can be accomplished only by using Ant. Is that so?
Thank you.
Eric
Joshua
March 4, 2010 at 9:27 am
Eric,
Sorry for the short delay in responding…
Typically I place the modules in the same project for ease of development.
I also utilize the compiler options to optimize the module for the project (i.e. the compiler reduces the size of the compiled module by removing classes that are already present in the ‘shell’ app).
That said, if you wanted to setup your project as separate projects there’s nothing stopping you. Your shell app will need to load the compiled module SWF at runtime. (I’m assuming you looking to leverage dynamically loaded moduels).
Of course you could use Ant as Cliff suggested to cross compile.