tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/685-shared-model-to-modulesRobotlegs: Discussion 2012-11-20T15:36:08Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/210704762012-11-19T17:49:31Z2012-11-19T17:49:31ZShared Model To Modules<div><p>I have a model instance in my Shell module , this model
implements an interface IAppModel. My application is loading module
swfs at runtime and i need to share my same model from shell, but i
want to use IAppModel in sub modules to reduce file size or dont
know duplication .<br>
i am using<br>
injector.mapSingleton(IAppModel);<br>
in module Context. This application works good at online server ,
sub module reads AppModel everything fine , but when developing sub
module individually, the module fails to load its visual assets and
i got these error messages in debuger , Note these errors were not
there when i was not using IAppModel injection.<br>
<code>[Fault] exception, information=TypeError: Error <a
href="/discussions/problems/1009" title="Discussion
#1009">#1009</a>: Cannot access a property or method of a
null object reference.</code> this is because there is no AppModel
to be injected , plz tell me how i can overcome this so that i can
develop sub module individually , or there is any other method to
share model</p></div>thexebtag:robotlegs.tenderapp.com,2009-10-18:Comment/210704762012-11-19T22:54:21Z2012-11-19T22:54:21ZShared Model To Modules<div><p>Hello,<br>
Mapping to an interface should be done like this:</p>
<p>injector.mapSingletonOf(IAppModel, AppModel);</p>
<p>Then you inject it like this:</p>
<p>[Inject] public var appModel: IAppModel;</p>
<p>Let me know if that solved your problem.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/210704762012-11-20T06:59:38Z2012-11-20T06:59:38ZShared Model To Modules<div><p>same as before , module fails to initialize , with same Null
refernce error , :(<br>
is there any other method to share model? i want to develop sub
modules unaffected as standalone</p></div>thexebtag:robotlegs.tenderapp.com,2009-10-18:Comment/210704762012-11-20T09:54:30Z2012-11-20T09:54:30ZShared Model To Modules<div><p>It’s hard to say what’s going on in your code,
without seeing it.Can you provide more details/code? :)</p>
<p>Some common problems:</p>
<ul>
<li>module is loaded before the mapping occurs (timing issues)</li>
<li>wrong mapping (as in your first post)</li>
<li>application domain not defined or wrong definition</li>
<li>module is not added to the stage (i.e. the swfloader or loader
if used in pure as3 projects)</li>
<li>wrong context definition for submodule</li>
<li>a mapping in submodule overwrites the mapping from shell</li>
<li>metadata gets stripped out (see -keep-as3-metadata+=Inject
-keep-as3-metadata+=PostConstruct for flex projects)</li>
<li>creating a new instance of the class (appModel=new
AppModel())</li>
</ul>
<p>You can also:<br>
- Use interfaces for module communication: <a href=
"http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf64277-7fea.html">
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c...</a></p>
<ul>
<li>Use a shared event dispatcher</li>
</ul></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/210704762012-11-20T14:01:51Z2012-11-20T14:01:51ZShared Model To Modules<div><p>Here is attached project<br>
Now i am facing Context problem at initializing , IAppModel is
instantiating successfully , i wonder if it will receive the
Shell's AppModel singleton at runtime?</p></div>thexebtag:robotlegs.tenderapp.com,2009-10-18:Comment/210704762012-11-20T14:51:02Z2012-11-20T14:51:02ZShared Model To Modules<div><p>I deleted the attachment, thus I’ll mark this discussion
as public again.</p>
<p>The problem was caused by the order of the mappings. You had
this:</p>
<p>mediatorMap.mapView(EffectsView, EffectsMediator);<br>
injector.mapSingletonOf(IAppModel,AppModel);</p>
<p>AppModel has been mapped after EffectsMediator has been already
created, therefore the injector didn’t have a rule for
injection.</p>
<p>Change it to this:</p>
<p>injector.mapSingletonOf(IAppModel,AppModel);//1 MODEL FIRST<br>
mediatorMap.mapView(EffectsView, EffectsMediator);//2 MEDIATOR
SECOND</p>
<p>It works!!</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/210704762012-11-20T15:26:27Z2012-11-20T15:26:27ZShared Model To Modules<div><p>thanks so much ondina , as u could see i am an intermediate
developer, i appreciate ur help a lot ,and looking to learn more
about these kind of basics</p></div>thexebtag:robotlegs.tenderapp.com,2009-10-18:Comment/210704762012-11-20T15:35:31Z2012-11-20T15:36:08ZShared Model To Modules<div><p>My pleasure :) Don’t worry, advanced users/devs can make
such a mistake too (i.e. order of the mappings).</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.