robotlegs / robotlegs-framework

An ActionScript 3 application framework for Flash and Flex
https://robotlegs.tenderapp.com/
MIT License
966 stars 261 forks source link

Potential confusion with hooks #116

Closed creynders closed 11 years ago

creynders commented 11 years ago

There seems to be a potentially confusing situation with hooks: when a class is passed its dependencies are injected, but with functions and objects this is not the case. If this is WAI then I think this should be made clear in the documentation. I'm not entirely sure whether it would be possible to inject into an anonymous function for instance, but certainly with mapped classes some kind of clarification is necessary. For instance:

//Foo
[Inject]
public function doFoo( bar : Bar ):void{
}

//MapTheShizzle
injector.map( IFoo ).toClass( Foo );
var foo : IFoo = injector.getInstance( IFoo );

eventCommandMap.map( 'FOO_EVENT' ).toCommand( SomeCommand ).withHooks( foo.doFoo );

You would expect Bar to be injected, wouldn't you? Or am I slowly but steadily stumbling into cuckoo-land here?

If you want I can take a look and see what I come up with.

darscan commented 11 years ago

Heya. There's no way to reflect over function references in AS3 unfortunately. Also, injecting into an existing object would be dangerous. So, I think the current implementation makes the most sense. But you're right about the docs - they could certainly be a bit more explicit about the conditions under which injection takes place.