Inject a class in a view

angelfilo's Avatar


22 Aug, 2010 02:17 PM

Hi all,
I'm trying to inject a class into a view,
in my command I use:

injector.mapClass(ClassToInject, ClassToInject);

later in the application inside in a view I use:

var injector:Injector = new Injector();
var myClassIstance:MyClass = injector.instantiate(MyClass);

inside the MyClass I have:

[Inject] public var classToInjectIstance:ClassToInject;

this Throws an error:

Injector is missing a rule to handle injection into target

I'm sure that I'm missing something.
Do you have any idea how I can do this?

  1. 1 Posted by Abel de Beer on 22 Aug, 2010 04:00 PM

    Abel de Beer's Avatar

    Something you need to realize about Robotlegs' MVC+S design:

    In the default Robotlegs MVC+S implementation, the View tier is represented by the Mediator actor. The specific view component the Mediator is mapped to is injected into the Mediator. The Mediator responds to the framework events and updates its view in response. This way, the view component has no knowledge of the application framework, which means it can be easily maintained and even reused because of this single responsibility approach. To map a View use:

    mediatorMap.mapView(MyViewComponent, MyMediator);

    I know this doesn't answer your problem. Generally the error above means that the class you're trying to inject hasn't been mapped when the class is instantiated. You say you're mapping the class in a Command which probably means it is mapped in response to some framework event. First check at which point the Command is instantiated and at a last resort you can try moving the mapClass statement to your Context.

    I hope to have been of help. :)

  2. 2 Posted by angelfilo on 22 Aug, 2010 04:28 PM

    angelfilo's Avatar

    Hi and thanks for your replay.
    you are probably right, I'm forcing the MVC to do something that should not do.
    I'm using mapView in my application for all the main functionalities, but in this specific case I was trying to create a small component, like a generic button, that at his creationcreation already contain label text, css, and other proprieties.
    This small component is used quite often in the application and for this reason I was reluctant to mediate it, and I tried to directly inject the needed proprieties.

    I'll try to move the map in the context...

    thanks again.

  3. Stray closed this discussion on 12 Feb, 2011 10:46 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac