tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/733-creating-boolean-valued-singletonRobotlegs: Discussion 2013-02-19T11:24:32Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/249551112013-02-15T12:32:35Z2013-02-15T12:32:35ZCreating Boolean valued singleton<div><p>Hi Chris,</p>
<p>mapValue(whenAskedFor:Class, useValue:Object,
named:String=""):*</p>
<p>When you do this:<br>
var serviceRequestPending:Boolean = false;<br>
injector.mapValue(Boolean, serviceRequestPending,
"serviceRequestPending");</p>
<p>the provided useValue will be used for every injection; the
injector won’t perform injection into this value.<br>
In other words, when you ask for an instance of type Boolean, named
‘serviceRequestPending’, you’ll always get the
instance with the value you provided (false).<br>
WIMIWIG :What I map is what I get ;)</p>
<p>If class A sets serviceRequestPending to true, the value of
serviceRequestPending in class B will still be false, unless you
remap serviceRequestPending before injecting it into class B, but
that wouldn’t make much sense.</p>
<p>Till wanted to introduce „live“ injections for
Swiftsuspenders 2, but, as far as I know, that didn’t
happen.</p>
<p>I understand that you’re expecting serviceRequestPending
to behave like a static variable of a Singleton class. If you
change its value in one class, you expect to get this value in
other classes as well, right?<br>
Class A:<br>
GlobalStaticClass.serviceRequestPending=true;<br>
Class B:<br>
trace(GlobalStaticClass.serviceRequestPending)// should be true<br>
GlobalStaticClass.serviceRequestPending=false;<br>
Class C:<br>
trace(GlobalStaticClass.serviceRequestPending)// should be
false</p>
<p>I think that a Model, mapped as a singleton (the good kind, with
a small "s"), having a property serviceRequestPending would serve
you better. Just saying:)</p>
<p>Ondina</p></div>Ondina D.F.