Skip to content
This repository has been archived by the owner on Mar 18, 2020. It is now read-only.

LaurentZuijdwijk/Apollo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

AS3 Apollo

Apollo is an dependency injection and message passing framework based on public interfaces.

It is lightweight, fast and easy to use.

Usage of introspection is optional, depending on the amount of control you want to have and on performance requirements.

Code sample

Code below will set-up a minimal actionscript application using Apollo. Notice the (nearly) complete lack of boiler-plate code.

We have to create an interface that will serve as a mapping proxy. In this example we will map the Person class to this interface.

public interface IPersonInjectable
{
   function set person(val:Person):void;
}

Set up our person value object.

public class Person{

   public var first_name:String;
   public var last_name:String;

   function Person(fist_name:String, last_name:String)
   {
	this.first_name = first_name;
	this.last_name = last_name;
   }
}

Our controller has to implement the above interface for the injection to work. Controllers will auto-register, so no code to be written.

public class PersonViewController extends Controller implements IPersonInjectable
{
   public function PersonViewController() 
   {
      super();
   }
 
   public function set person(val:Person):void
   {
      view.person = val;
      trace(val.first_name + ' ' + val.last_name)
   }
}

In our main class we have to do two things for this example to work.

  • Register interfaces
  • Instatiate a controller

Now we can inject a message of type Person. Magic.

// Register our interfaces used to construct our mappings
Injector.interfaces = [IPersonInjectable];

// Create our controller
new PersonViewController();
 
//Inject a message
Injector.inject(new Person('Laurent', 'Zuijdwijk'))

Performance considerations

I didn't do any benchmarking yet, but I expect performance to be pretty good. The introspection part is pretty lightweight, mainly because it is only done on a limited set of interfaces. But if you want to contruct mappings manually, this is possible as well. See the example below.

var injectorMap:Vector.<InjectorMapping> = new Vector.<InjectorMapping>();
injectorMap.push(new InjectorPropertyMapping(IPersonInjectable, 'person', Person));
Injector.model = injectorMap;

About

Apollo is an dependency injection and messaging framework. It can be used as the basis for Actionscript MVC projects.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published