thedevstop / asfac

A simple, fast IOC container for use in ActionScript projects
MIT License
0 stars 0 forks source link

Support multiple registration for a single type #25

Closed JoeRobich closed 8 years ago

JoeRobich commented 10 years ago

Problem:

I have multiple types of ITask that I would like to register with the factory and retrieve all at once later when displaying them to the user.

Suggestion:

Multi-register types for an interface

 // Standard
 factory.register(NaiveStrategy, IStrategy, NaiveStrategy, false);
 factory.register(ExpertStrategy, IStrategy, ExpertStrategy, false);
 var strategies:Array = factory.resolveAll(IStrategy);

 // Fluent
 factory.register(NaiveStrategy).forType(IStrategy);
 factory.register(ExpertStrategy).forType(IStrategy);
 var strategies:Array = factory.resolveAll(IStrategy);

Since we make multiple registrations for a type by changing scope, provide a method for resolving a type from all scopes. Make it easy to create these registrations in the Fluent interface by adding a forType to complement asType. forType will set the scope name based on the registered instance.

JoeRobich commented 10 years ago

First spike of the functionality. Looking for comment. Still need to write tests.

JoeRobich commented 10 years ago

Added minimal tests around new functionality.

druttka commented 10 years ago

Seems legit. I don't have an ActionScript environment right now, so I won't be pulling this and running the tests, etc. If the tests are passing and it enables your use case, merge at will =)