首先我使用mvvmcross version 3.0.13
. 当一个类继承自基类时,基类继承自MvxViewModel
,则不会从 IoC 调用 Init 方法。当前丑陋的解决方法是在构造函数中调用 Init。这可能是一个错误还是有其他模式可以使用?
在这两个类(该基的基类和子类)中,它都不会被调用。例如:
public class BaseViewModel : MvxViewModel
{
protected CDataImportService DataImportService { get; private set; }
protected CSettingService SettingService { get; private set; }
protected CDataService DataService { get; private set; }
protected CDocumentService DocumentService { get; private set; }
public BaseViewModel(IDataService objDataService, IDataImportService objDataImportService, IDocumentService objDocumentService, ISettingService objSettingService)
{
DataImportService = (CDataImportService)objDataImportService;
SettingService = (CSettingService)objSettingService;
DataService = (CDataService)objDataService;
DocumentService = (CDocumentService) objDocumentService;
}
public void Init()
{
Mvx.Trace("Init called in {0}", GetType().Name);
}
}
public class DocumentsViewModel : BaseViewModel
{
public MenuViewModel(IDataService objDataService, IDataImportService objDataImportService, IDocumentService objDocumentService, ISettingService objSettingService)
: base(objDataService, objDataImportService, objDocumentService, objSettingService)
{
}
}