The Prana IoC Container

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    The Prana IoC Container - Presentation Transcript

    1. Christophe Herreman www.herrodius.com Adobe Usergroup Belgium 26 january 2008
      • What is Prana ?
      • An Inversion of Control (IoC) Container for ActionScript 3.0
      • Based on Java Spring
      • Current release 0.4 (released today)
      • www.pranaframework.org
      • What is Prana ?
      • Cairngorm support
      • PureMVC support
      • Reflection API
      • Several Utilities
      • What is Inversion of Control ?
      • Inversion of Control, also known as IOC, is an object-oriented programming principle that can be used to reduce coupling inherent in computer programs.
      • What is Inversion of Control ?
      • Scenario: Class A uses class B to get something done
      • Class A {
      • public function doSomething():* {
      • var b:B = new B();
      • var somethingDone:* = b.getSomethingDone();
      • return markAsDone(somethingDone);
      • }
      • }
      • Notice :
      • can’t switch the implementation of B
      • can’t unit test in isolation
      • Types of Inversion of Control ?
      • Dependency Lookup
        • Dependency Pull
        • Contextualized Dependency Lookup
      • Dependency Injection
        • Constructor Injection
        • Setter Injection
      • Dependency Pull
      • Class A {
      • public function doSomething():* {
      • var b:B = UberModel.getInstance().b;
      • var somethingDone:* = b.getSomethingDone();
      • return markAsDone(somethingDone);
      • }
      • }
      • UberModel.getInstance().b = new B();
      • var a:A = new A();
      • a.doSomething();
      • Contextualized Dependency Lookup
      • Class A {
      • public function doSomething(model:UberModel):* {
      • var somethingDone:* = model.b.getSomethingDone();
      • return markAsDone(somethingDone);
      • }
      • }
      • var model:UberModel = UberModel.getInstance();
      • var a:A = new A();
      • a.doSomething(model);
      • Constructor Injection
      • Class A {
      • public function A(b:B) {
      • this.b = b;
      • }
      • public function doSomething():* {
      • var somethingDone:* = b.getSomethingDone();
      • return markAsDone(somethingDone);
      • }
      • }
      • var a:A = new A(new B());
      • a.doSomething();
      • Setter Injection
      • Class A {
      • private var b:B;
      • public function set b(value:B):void {
      • this.b = value;
      • }
      • public function doSomething():* {
      • var somethingDone:* = b.getSomethingDone();
      • return markAsDone(somethingDone);
      • }
      • }
      • var a:A = new A();
      • a.b = new B();
      • a.doSomething();
      • Inversion of Control?
      • Prefer setter injection
      • Type to interfaces !!!
      • Centralized configuration
      • Maintainability
      • Reusability
      • Testability
      • ...
      • Though counter-intuitive at first !
    2. What is an IoC Container ? Creates and assembles components/objects and manages their lifecycle. Prana uses an XML dialect to define the “application context” (what objects are available and how they are related)
    3. The Application Context // setter injection <objects> <object id=“a” class=“A”> <property name=“b” ref=“b”/> </object> <object id=“b” class=“B”/> </objects> // constructor injection <objects> <object id=“a” class=“A”> <constructor-arg ref=“b”/> </object> <object id=“b” class=“B”/> </objects>
    4. Working with the IoC container <mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; creationComplete=&quot;onCreationComplete()“> ... private function onCreationComplete():void { _objectsLoader = new XmlObjectDefinitionsLoader(); _objectsLoader.addEventListener(ObjectDefinitionsLoaderEvent.COMPLETE, onObjectDefinitionsLoaderComplete); _objectsLoader.load(&quot;application-context.xml&quot;); } private function onObjectDefinitionsLoaderComplete(event:ObjectDefinitionsLoaderEvent):void { var container:ObjectContainer = _objectsLoader.container; var a:A = container.getObject(“a”); } ... </mx:Application>
      • Conclusion
      • Objects defined in external XML file
      • Loaded at runtime
      • Managed by container
      • Deploy your application with different configurations without recompiling!
      • Resources
      • www.pranaframework.org
      • www.herrodius.com
    5. Questions?

    + Christophe HerremanChristophe Herreman, 2 years ago

    custom

    863 views, 0 favs, 1 embeds more stats

    Talk about the Prana IoC Container at the Adobe AIR more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 863
      • 862 on SlideShare
      • 1 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 10
    Most viewed embeds
    • 1 views on http://www.herrodius.com

    more

    All embeds
    • 1 views on http://www.herrodius.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories