My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
FabricationIoC  
IoC mechanism for Fabrication actors.
Featured
Updated Sep 11, 2010 by rafael.s...@gmail.com

Introduction

With version 0.7.1 a brand new mechanism is being introduced - IoC for Fabrication actors. It simplyfies the way you can retrieve mediators/proxies instances within body of your classes.

Requirements

This feature needs Fabrication version 0.7.1 or above.

Usage Scenarios

Let say you have your startupCommand like this one:

MyApplicationStartupCommand.as

package  controller {
    import org.puremvc.as3.multicore.interfaces.INotification;
    import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;

    import spark.components.Application;

    public class MyApplicationStartupCommand extends SimpleFabricationCommand {


        override public function execute(notification:INotification):void
        {
            registerProxy( MyApplicationProxy1( "MyAppProxy1", { someData:"DataFromProxy1" } );
            registerProxy( MyApplicationProxy2( "MyAppProxy2", { someData:"DataFromProxy2" } );
        }
    }
}

and your application mediator, when you want to get reference to one of registered proxies:

MyApplicationMediator.as

package view {
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.mediator.FlexMediator;		

	public class MyApplicationMediator extends FlexMediator {
		
		static public const NAME:String = "MyApplicationMediator";
		
		public function MyApplicationMediator(viewComponent:Object) {
			super(NAME, viewComponent);
		}
					
		override public function onRegister():void {
                        super.onRegister();
			var myProxy:MyApplicationProxy1 = retrieveProxy( "MyAppProxy1" ) as MyApplicationProxy1;
		}
		
	}
}

Injection by class

Using new IoC mechanism you can do something like this:

MyApplicationMediator.as

package view {
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.mediator.FlexMediator;		

       	public class MyApplicationMediator extends FlexMediator {
	
		static public const NAME:String = "MyApplicationMediator";

                [InjectProxy]
                public var proxy:MyApplicationProxy;
		
		public function MyApplicationMediator(viewComponent:Object) {
			super(NAME, viewComponent);
		}
				
	}
}

Injection by type

Injecting actors by type ( and it's name ) give you possibility to simple and quick way to switch between instances of same type. For example, we can simply inject instance of some proxy ( IProxy ) named "MyAppProxy1":

MyApplicationMediator.as

package view {
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.mediator.FlexMediator;		

       	public class MyApplicationMediator extends FlexMediator {
		
		static public const NAME:String = "MyApplicationMediator";

                [InjectProxy(name="MyAppProxy1"]
                public var proxy:IProxy;
		
		public function MyApplicationMediator(viewComponent:Object) {
			super(NAME, viewComponent);
		}
				
	}
}

We can change metadata name argument to "MyAppProxy2" to have another instance injected.

Additional info

  • you can use the same mechanism for mediators injection ( [ InjectMediator ] metatag ).
  • By design, you can inject mediators and proxies into commands and mediators. Proxy can have injected only other proxies.
  • In commands all injected references are disposed when command execution is finished. In mediators all references are disposed on mediator remove. To clean same references in your proxy you have to use Proxy.dispose method.

Examples

  1. IoC mechanism example Demo Source
Comment by mellom...@gmail.com, Jul 6, 2010

Can we see an example of a mediator being injected?? How would you assign the viewComponent?

Comment by k.swisul...@gmail.com, Jul 11, 2010

doesn't work with FlashApplication? version (in this case would be FabricationMediator?).Does it works Only with FlexMediators? only?

Comment by project member rafael.s...@gmail.com, Jul 14, 2010

@mellomike I will add a simple example today @k.swisulska You should use FlashMediator? in tour flash application. In 0.7.1 version only FlexMediator? has abbility to inject properties, today version 0.7.2 will be released and FlashMediator? should work also.

Comment by byniu...@gmail.com, Jul 14, 2010

RE:0.7.2 While compiling with FlashApplication? (Pure As3)am getting missing resource error: VerifyError?: Error #1014: Nie znaleziono klasy mx.modules::Module. , guess some mx stuff shouldn't be there?

Comment by project member rafael.s...@gmail.com, Jul 14, 2010

Yes, you're right. I'll fix it, upload a new version and let you know

Comment by gunsling...@gmail.com, Aug 21, 2010

doesn't work in FlashBuilder4?.

declaring a public var outside the class definition throws an error in flash builder:

Beschreibung Ressource Pfad Position Typ A file found in a source-path can not have more than one externally visible definition.

Comment by project member rafael.s...@gmail.com, Aug 22, 2010

public var outside class definition won't work in any editor :). There was mistake in example - of course injected filed has to be declared inside class definition. It is fixed now.

Comment by gunsling...@gmail.com, Aug 22, 2010

sorry, maybe i see some needed dependencies not. but even when inject metadata with public scoped variable is in class definition, i get typeerror 1009: access to null object

i use sdk 3.5 and the latest fabrication swc...

i already studied your examples, but cannot find any difference to my code. i would love to use this feature, cause retrieving stuff from puremvc sucks...

Comment by project member rafael.s...@gmail.com, Aug 22, 2010

If this is possible, please email me your code so I can quickly find the issue. If it is ok, send it to fabrication@googlecode.com

Comment by broadysm...@gmail.com, Jun 27, 2011

Looks like Injecting works differently in mediators and commands. Same code: InjectProxy? public var so:SharedObjectProxy?;

fires onRegister method when put in mediator and doesn't when in a command.

Comment by project member rafael.s...@gmail.com, Jun 29, 2011

Hi, Which version of fabrication do you use? In Command injected items ( proxies, mediators, etc ) should be available in execute method. The most important thing is to remember about super.execute() call.

Comment by broadysm...@gmail.com, Apr 2, 2012

Hi, sorry for late response, I think I didn't get any reminder on email. It worked, but that makes a question when else do I need to call super.execute (), or more specifically, what does the superclass execute?


Sign in to add a comment
Powered by Google Project Hosting