Nested Models - Injection Best Practices

Theo's Avatar

Theo

13 Feb, 2012 10:51 PM

Im new to RL and really to MVC as well so I may just not be thinking about this correctly but heres the situation:

I have some nested models - A FamilyModel includes several UserModels. During my startup, I create the FamilyModel manually because I pass its id from some config stuff. It makes some remote calls to fetch some data and then creates the user models, also which get passed an ID during construction, and then do some more remote calls to load their data.

The issue is that now if I want to use DI in the user models (for example to inject the api calling service), I need to inject the injector into the family model and manually call injectInto on the user models after I instantiate them.

I guess the way I'm thinking about things, I still want to manually construct things at least with a little bit of info (configuration, id, etc) which then means I need to always use injectInto.

Can someone clarify whats the RL way to do this?

  1. Support Staff 1 Posted by creynders on 14 Feb, 2012 07:16 AM

    creynders's Avatar

    In RL models aren't supposed to call remote services, not directly and not through composed delegate classes. In fact application models can be entirely different from domain models. This is why we have the S in MVCS: services. You create services that call the remote API and pass the returned data to commands that in turn populate models if need be. The idea is to separate the data model from the data retrieval method, since it makes the system more flexible.

    Then, core actors should in general never be responsible for composing other core actors. This is what we have commands for, that optionally can use factories if you need a centralized composition mechanism.

    And it's perfectly possible to have actors that need to be configured and still use the auto DI. You can have constructor injection or you can use the PostConstruct meta tag to have a method automatically called after the injections.

  2. Ondina D.F. closed this discussion on 29 Feb, 2012 11:23 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac