If a view model can only exist in conjunction with another, I create a strong relationship. That is the owning view model will have a direct reference to one or more of the dependent view models. If, on the other hand, a view model should be able to exist with or without another, I take a loosely-coupled approach where they communicate via an event bus.
In terms of using DI with MVVM, absolutely you can combine the two. It's as simple as:
public class MyViewModel
{
private readonly IMyDependency _myDependency;
public MyViewModel(IMyDependency myDependency)
{
_myDependency = myDependency;
}
}
Note, however, that this assumes a "view model first" approach to MVVM, which has its drawbacks.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…