Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/LaurentZuijdwijk/Apollo
Apollo is an dependency injection and messaging framework. It can be used as the basis for Actionscript MVC projects.
https://github.com/LaurentZuijdwijk/Apollo
Last synced: about 2 months ago
JSON representation
Apollo is an dependency injection and messaging framework. It can be used as the basis for Actionscript MVC projects.
- Host: GitHub
- URL: https://github.com/LaurentZuijdwijk/Apollo
- Owner: LaurentZuijdwijk
- Archived: true
- Created: 2011-08-13T13:13:58.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-08-24T23:02:41.000Z (over 13 years ago)
- Last Synced: 2024-05-06T10:35:37.498Z (8 months ago)
- Language: ActionScript
- Homepage:
- Size: 129 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.mkd
Awesome Lists containing this project
- awesome-actionscript-sorted - Apollo - Apollo is an dependency injection and messaging framework. It can be used as the basis for Actionscript MVC projects. (Frameworks / MVC Framework)
README
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.
```actionscript
public interface IPersonInjectable
{
function set person(val:Person):void;
}
```Set up our person value object.
```actionscript
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.
```actionscript
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 controllerNow we can inject a message of type Person. Magic.
```actionscript
// 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.
```actionscript
var injectorMap:Vector. = new Vector.();
injectorMap.push(new InjectorPropertyMapping(IPersonInjectable, 'person', Person));
Injector.model = injectorMap;
```