tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/497-robotlegs-140-swiftsuspenders-160-produces-warning-injector-already-has-a-rule-for-typeRobotlegs: Discussion 2018-10-18T16:35:25Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/64074842011-04-03T13:01:00Z2011-04-03T13:01:00ZRobotlegs 1.4.0 + SwiftSuspenders 1.6.0 produces "Warning: Injector already has a rule for type...."<div><p>Hi Luke,</p>
<p>you shouldn't be seeing these messages in this situation. The
messages were a recent addition after a few people ran into
problems where they accidentally over-wrote mappings, it was
decided that a warning would alert people to that situation without
breaking existing code.</p>
<p>Is the code you've posted the entire code for the project? And
the project isn't modular?</p>
<p>If so I'll quickly create a mini-project and see if it also
happens here and then we can work out what's causing it.</p>
<p>Thanks,</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/64074842011-04-03T13:11:25Z2011-04-03T13:11:26ZRobotlegs 1.4.0 + SwiftSuspenders 1.6.0 produces "Warning: Injector already has a rule for type...."<div><p>Hi Stray,</p>
<p>Ah that makes sense, you wouldn't want users overwriting the
built-in mappings and breaking the framework.</p>
<p>Yep, that's the entire source code, and it's not being loaded as
a module. I included robot legs and swift suspenders source code
directly from git.</p></div>lukevanintag:robotlegs.tenderapp.com,2009-10-18:Comment/64074842011-04-03T14:21:47Z2011-04-03T14:21:47ZRobotlegs 1.4.0 + SwiftSuspenders 1.6.0 produces "Warning: Injector already has a rule for type...."<div><p>Cool - I'm looking into it now then!</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/64074842011-04-03T15:03:45Z2011-04-03T15:03:45ZRobotlegs 1.4.0 + SwiftSuspenders 1.6.0 produces "Warning: Injector already has a rule for type...."<div><p>Hi Luke,</p>
<p>I know what the cause is. In AS3, we'd instantiate the context
using the constructor. But with flex, you're skipping the
constructor (which is fine because the params are optional) but
then you're setting the contextView as a parameter.</p>
<p>This then causes the app to go through the injection mapping
process again. And currently we're not manually unmapping the
injector mappings first.</p>
<p>I'll just confirm with Till, Shaun and Joel exactly what the
correct behaviour should be, and then I'll add some tests and make
the changes on the repo.</p>
<p>Thanks for bringing this to our attention! I only use pure AS3
myself so I hadn't come across it.</p>
<p>In the meantime, you can replace the robotlegs Context.as with
the following:<br>
<a href=
"https://gist.github.com/900465">https://gist.github.com/900465</a></p>
<p>I've only made 2 changes - line 138 is added to the <code>set
contextView</code> method to make sure we clean up the mappings
before re-doing startup, and that function -
<code>unmapInjections</code> is at line 256.</p>
<p>I don't think it's going to be any more complex than that, as
autostartup checks whether the contextView has a .stage property
before running, but I need to add some tests so if you see anything
else that's out of place do let us know.</p>
<p>Thanks!</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/64074842011-04-03T15:58:18Z2011-04-03T15:58:19ZRobotlegs 1.4.0 + SwiftSuspenders 1.6.0 produces "Warning: Injector already has a rule for type...."<div><p>Hi Stray</p>
<p>Thanks so much for looking into this, your fix works like a
charm!</p>
<p>It makes sense now seeing what you did, basically un-mapping all
the classes and then immediately re-mapping them.</p>
<p>It seems a pity to have to do this, you would think that SS
should be able to check against the references when doing the
mappings, and ignore them if nothing has changed. On the other hand
I suppose the overhead would be the same as un-mapping and
re-mapping but it would make it easier for developers who override
the mapInjections() method to not have to also create the
unmapInjections() method.</p>
<p>I tried this out by adding an additional check in
InjectionConfig.as at lines 74-75:<br></p>
<pre>
<code>if (m_result.getResponse(m_injector) === result.getResponse(m_injector))
return;</code>
</pre>
<p>This bails out of showing a warning or assigning the injector if
it's being re-assigned with the same value (if nothing has
changed).</p>
<p>This reduces some of the warnings but I'm obviously still
missing something because it still complains about
DisplayObjectContainer, ICommandMap, IMediatorMap, and IViewMap.
Perhaps I should post on SS issues about this.</p></div>lukevanintag:robotlegs.tenderapp.com,2009-10-18:Comment/64074842011-04-03T16:08:21Z2011-04-03T16:08:21ZRobotlegs 1.4.0 + SwiftSuspenders 1.6.0 produces "Warning: Injector already has a rule for type...."<div><p>Hi Luke,</p>
<p>I'm just in the process of updating a repo of the project that
has test coverage for this, so if you can bear with me for another
half hour you'll have a version that you can check against - you
shouldn't still be seeing those warnings at all.</p>
<p>Re your 'it should...' unfortunately we can't change that sort
of behaviour mid-version, because people might be relying on
mapping overwrites in their code, which is why the decision was
taken between us and Till that a warning was the best plan for
now.</p>
<p>SS 2.0 will have a more sophisticated protection.</p>
<p>Unfortunately adding the tests you described will also have a
performance impact, and so we're reluctant to add code like that in
RL 1.x as it might mean that someone updating to the next version
suddenly finds their project isn't viable.</p>
<p>As it is - in the end - only a trace - a developer is absolutely
free to just ignore those (or remove them from the SS source) and
not bother over-writing.</p>
<p>Till is one of the support team here so it makes no odds where
you report it - probably better to report SS issues here if they
relate to RL.</p>
<p>I'm emailing him on this as well.</p>
<p>I'll post back as soon as my repo is ready for you to pull
from,</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/64074842011-04-03T16:35:48Z2011-04-03T16:35:48ZRobotlegs 1.4.0 + SwiftSuspenders 1.6.0 produces "Warning: Injector already has a rule for type...."<div><p>Ok - I've updated (with new tests) and you can pull from my repo
here:</p>
<p><a href=
"https://github.com/Stray/robotlegs-framework">https://github.com/Stray/robotlegs-framework</a></p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/64074842011-04-03T16:55:40Z2011-04-03T16:55:40ZRobotlegs 1.4.0 + SwiftSuspenders 1.6.0 produces "Warning: Injector already has a rule for type...."<div><p>Wow Stray! I'm super impressed by the quick turn-around. Thank
you so much for helping out :)</p></div>lukevanin