tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/257-inject-value-in-a-viewRobotlegs: Discussion 2018-10-18T16:35:16Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/26602222010-08-22T14:17:57Z2010-08-22T15:04:02ZInject a class in a view<div><p>Hi all,<br />
I'm trying to inject a class into a view,<br />
in my command I use:<br />
</p>
<pre><code>injector.mapClass(ClassToInject, ClassToInject);</code></pre>
<p>later in the application inside in a <strong>view</strong> I use:<br />
</p>
<pre><code>var injector:Injector = new Injector();
var myClassIstance:MyClass = injector.instantiate(MyClass);
addChild(myClassIstance);</code></pre>
<p>inside the MyClass I have:<br />
</p>
<pre><code>[Inject] public var classToInjectIstance:ClassToInject;</code></pre>
<p>this Throws an error:<br />
</p>
<pre><code>Injector is missing a rule to handle injection into target</code></pre>
<p>I'm sure that I'm missing something.<br />
Do you have any idea how I can do this?<br />
Thanks!</p></div>angelfilotag:robotlegs.tenderapp.com,2009-10-18:Comment/26602222010-08-22T16:00:25Z2010-08-22T16:02:39ZInject a class in a view<div><p>Something you need to realize about Robotlegs' MVC+S design:</p>
<p>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:</p>
<p><code>mediatorMap.mapView(MyViewComponent, MyMediator);</code></p>
<p>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 <code>mapClass</code> statement to your Context.</p>
<p>I hope to have been of help. :)</p></div>Abel de Beertag:robotlegs.tenderapp.com,2009-10-18:Comment/26602222010-08-22T16:28:14Z2010-08-22T16:28:15ZInject a class in a view<div><p>Hi and thanks for your replay.<br />
you are probably right, I'm forcing the MVC to do something that should not do.<br />
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.<br />
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.</p>
<p>I'll try to move the map in the context...</p>
<p>thanks again.</p></div>angelfilo