tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/903-singleton-viewfactory-class-giving-out-null-valueRobotlegs: Discussion 2018-10-18T16:35:46Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/253531442013-02-26T19:42:21Z2013-02-26T19:58:56ZSingleton ViewFactory class, giving out null value<div><pre>
<code> context.injector.map(StatsModel).asSingleton();
context.injector.map(XMLLoaderService).asSingleton();
context.injector.map(Factory).asSingleton(); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Factory Class</code>
</pre>
<p>The Factory class resides in view package and retains all the
instances of views . ( inside swc.view )</p>
<p>I am able to inject contextView inside StatsModel class and get
a value<br></p>
<pre>
<code> [Inject]
public var contextView:ContextView;</code>
</pre>
<p>but doing the same in Factory class , gives out null .</p>
<p>However, it seems ok but I want to confirm, if making a
singleton of Factory class ( that resides in view package ) is
normal and allowed ?</p>
<p>After that my concern is about accessing the Factory class from
view.swc ( SWC file ) . When i opened the swc file, and saw the
Factory class, the [Inject] metatags were gone! They were showing
as plain variables. Is that the reason i am getting null values
?</p>
<p>V.</p></div>vishwas.gagranitag:robotlegs.tenderapp.com,2009-10-18:Comment/253531442013-02-27T18:29:26Z2013-02-27T18:29:26ZSingleton ViewFactory class, giving out null value<div><p>ok.. i concluded with the following:<br>
view.swc is not responsible for null value. The injectors are
working fine everywhere ( In mediators, in Model singleton, except
the singleton Factory class inside "View" package.</p>
<p>So, does that mean, unlike statsmodel ( singleton of model
package) if singletons are used in view packages, the [Inject]
won't work ? It's not supposed to be used there ?</p></div>vishwas.gagranitag:robotlegs.tenderapp.com,2009-10-18:Comment/253531442013-02-27T21:59:00Z2013-02-27T21:59:00ZSingleton ViewFactory class, giving out null value<div><p>Hi. The package should have no effect on things. Something else
must be causing the issue. How do you instantiate your Factory?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/253531442013-02-27T22:04:10Z2013-02-27T22:04:10ZSingleton ViewFactory class, giving out null value<div><p>Oh wait, I just saw this:</p>
<blockquote>
<p>When i opened the swc file, and saw the Factory class, the
[Inject] metatags were gone! They were showing as plain variables.
Is that the reason i am getting null values ?</p>
</blockquote>
<p>Maybe. The Flash IDE strips out non-standard metadata tags
during compilation. You need to tell it not to by selecting "Export
SWC" in the publish settings. Even if you are only using the SWF
you need to select this in order to keep the metadata tags.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/253531442013-02-28T05:32:11Z2013-02-28T05:37:54ZSingleton ViewFactory class, giving out null value<div><pre>
<code>Maybe. The Flash IDE strips out non-standard metadata tags during compilation. You need to tell it not to by selecting "Export SWC" in the publish settings. Even if you are only using the SWF you need to select this in order to keep the metadata tags.</code>
</pre>
<p>Well, first thing is i am no longer using the Flash IDE now. And
second is, i checked it afterwards, and found that even after
stripping the tags, it's not responsible for null values. (
Something like, it shows the meta tags stripped off... but still
has the metatag information somewhere inside itself). I checked
this by making another small example.</p>
<p>As i said, i don't instantiate the Factory class. It's a
singleton, and has been mentioned in AppConfig.as ( the same way a
Model class is mentioned )</p>
<pre>
<code> context.injector.map(Factory).asSingleton();</code>
</pre>
<p>It's placed in swc.view package. And is used to instantiate
views as per demand via Command classes. I get the "Factory"
instance in the Command classes by :</p>
<pre>
<code>[Inject]
public var factory:Factory;</code>
</pre></div>vishwas.gagranitag:robotlegs.tenderapp.com,2009-10-18:Comment/253531442013-02-28T05:54:50Z2013-02-28T05:54:50ZSingleton ViewFactory class, giving out null value<div><p>Ah!.. finally got it.<br>
I was trying to get the injected contextView inside the constructor
of Factory class. I am using it in the other functions, and i am
getting the values. I just checked getting the value of contextView
inside the constructor of Model class too.. and found the same
thing "null". So, it seems that injected objects are not supposed
to be used inside the constructor functions.<br>
Anyways, got it solved.</p>
<p>Thnx!<br>
V.</p></div>vishwas.gagrani