Typically, the ViewModel goes to the service (what is its name Prism) to obtain the necessary data. This service is ported to the ViewModel via the DI (Constructor Injection), although you can follow this other path through the ServiceLocator.
Therefore, your ViewModel will refer to a service that will abstract the retrieval of your data. Data can come from a DB file, XML, which knows ... there is an abstraction. Thus, for your case with IData, a reference to this type will occur at some point in the ViewModel, but not through any of the DIs. If your IoC framework allows (Prism), you create a mapping of interface types to specific types, and then extract those types through your container; this is the case with Oneness.
Here is a brief example ... Scripts are attached to the view, and the ViewModel is entered into the view. Note the use of IScriptService to retrieve data. The returned data is a set of IScript types, however, we never officially introduced this type in the ViewModel, because we do not care about the type as a single object, which we care about the type in the scale of greatness.
public ScriptRepositoryViewModel(IUnityContainer container, IScriptService scriptService, IEventAggregator eventAggregator) { _container = container; _scriptService = scriptService; _eventAggregator = eventAggregator; } public ICollectionView Scripts { get { if (_view == null) { _view = CollectionViewSource.GetDefaultView(_scriptService.Scripts); _view.Filter = Filter; } return _view; } }
When you go to the view, the same case may be there, the view will be introduced via DI (inline constructor) using the ViewModel. I would not make other ViewModels depend on each other, isolate them. If you begin to see the need for a connection, take a look at the data that you are trying to transfer, most often that this data should be abstracted further and not tied to any ViewModel.
Aaron mciver
source share