tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/11363-injection-support-with-a-contextviewRobotlegs: Discussion 2014-07-25T09:15:23Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/335645792014-06-27T07:46:23Z2014-06-28T12:55:20ZInjection Support without a ContextView<div><p>Hi Dan,</p>
<p>Yes, you can do that.</p>
<p>Your custom MVC Bundle could look like this:</p>
<pre>
<code>
public class CustomMVCSBundle implements IBundle
{
public function extend(context:IContext):void
{
context.install(
EventDispatcherExtension,
EventCommandMapExtension,
LocalEventMapExtension
);
}</code>
</pre>
<p>Your Context:</p>
<pre>
<code>
private var _context:IContext;
private function createRLContext():void
{
_context = new Context();
_context.install(CustomMVCSBundle);
_context.configure(ViewLessConfig);
_context.initialize();
}</code>
</pre>
<p>Note the last line: <strong>_context.initialize();</strong> You
have to initialize your viewless context manually!</p>
<pre>
<code>
public class ViewLessConfig implements IConfig
{
[Inject]
public var injector:IInjector;
[Inject]
public var commandMap:IEventCommandMap;
public function configure():void
{
injector.map(SomeModel).asSingleton();
commandMap.map(SomeEvent.TRIGGER_SOMETHING)
.toCommand(SomeCommand);
}
}</code>
</pre>
<p>The only problem with a viewless context is that you can't use
the Modularity extension, because, as far as I know, it needs a
contextView.</p>
<p>Does that help answer your question?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/335645792014-06-27T11:26:21Z2014-06-28T12:55:19ZInjection Support without a ContextView<div><p>Hi Dan. Yes, your modules make sense, at least for me. I am
working with<br>
"faceless" modules too. For example, I have a database access
module with lots of mappings that are not relevant for the rest of
the application.<br>
Putting this logic inside a module should speed things up, I
think.<br>
Anyway, I have never made a performance test.</p>
<p>Meil Manuell wrote an excellent article about this modules
at<br>
<a href=
"http://statemachine.org/?p=492">http://statemachine.org/?p=492</a>.
Inspired on it, I made my own<br>
implementation for RL2. Basically, you need to create a context for
the<br>
module and install+configure whatever you want on it, then add it
as a<br>
child of your current context, and lastly initialize it. You could
like to<br>
save a reference to the created context in case you want to destroy
it<br>
(unload module). In that case, you only need to call it's destroy()
method, and it will be automatically removed from the main context.
Note<br>
also that you will inherit parent dependencies...cool!</p>
<p>El Jue, 26 de Junio de 2014, 7:42 pm, dan escribió:</p></div>greenLEDtag:robotlegs.tenderapp.com,2009-10-18:Comment/335645792014-06-28T12:58:01Z2014-06-28T12:58:01ZInjection Support without a ContextView<div><p>@greenLED Thank you for mentioning 2 important things, that
where missing in my code example, namely the fact that the main
context should add the child context through context.addChild(),
and that it should also remove it, when needed!<br>
My example was based on the one I posted in another discussion
(<a href=
"http://knowledge.robotlegs.org/discussions/robotlegs-2/10174-is-there-any-way-to-easy-destroy-config#comment_32145927">http://knowledge.robotlegs.org/discussions/robotlegs-2/10174-is-the...</a>),
but when I changed the names and deleted the lines that were
referring to a child context with a contextView, I deleted the
context.addChild(childContext);<br>
as well. Sorry about that.</p>
<pre>
<code>
private var _parentContext:IContext;
private var _childContext:IContext;
private function createChildContext():void
{
_childContext = new Context();
_childContext.install(CustomMVCSBundle);
_childContext.configure(ChildContextConfig);
//
_parentContext.addChild(_context)
_childContext.initialize();
}
....
private function destroyChildContext():void
{
_parentContext.removeChild(_childContext);
_childContext.destroy();
}</code>
</pre>
<p>Neil's solution looks nice. I haven't seen it until now. Thanks
for the link.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/335645792014-06-28T13:47:18Z2014-06-28T13:47:18ZInjection Support without a ContextView<div><p>Is it necessary for the contexts to have a parent child
relationship? I<br>
actually don't want them to have anything to do with one another. I
also<br>
don't have control over which context will be initialized
first!</p></div>dantag:robotlegs.tenderapp.com,2009-10-18:Comment/335645792014-06-28T16:25:02Z2014-06-28T16:25:02ZInjection Support without a ContextView<div><blockquote>
<p>I actually don't want them to have anything to do with one
another.</p>
</blockquote>
<p>In this case the code from my first post would suffice. And,
when/if you needed to destroy it, you'd use context.destroy().</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/335645792014-06-28T21:31:50Z2014-06-28T21:31:50ZInjection Support without a ContextView<div><p>Are you meaning a context chain like</p>
<p>mainContext {modA {modB {modC {...}}}}</p>
<p>It is not necessary. Just add them as childs of your main
context, like</p>
<p>mainContext {modA{}, modB{}, modC {}, ...}</p>
<p>This way, the main context knows how to create/destroy each
module. Of<br>
course, you could have modules inside modules using this same
mechanism, I<br>
think (never tried).</p>
<p>El Sab, 28 de Junio de 2014, 9:47 am, dan escribió:</p></div>greenLEDtag:robotlegs.tenderapp.com,2009-10-18:Comment/335645792014-06-29T20:22:56Z2014-06-29T20:22:56ZInjection Support without a ContextView<div><p>Awesome thanks. Thanks for the preview I'll try this out
asap.</p></div>dantag:robotlegs.tenderapp.com,2009-10-18:Comment/335645792014-06-30T00:41:47Z2014-06-30T00:41:47ZInjection Support without a ContextView<div><p>You're welcome. Good luck.</p>
<p>El Dom, 29 de Junio de 2014, 4:22 pm, dan escribió:</p></div>greenLED