WPF Prism 7.0+ IContainerRegistry (依赖注入)
示例下载:PrismCore
注入接口:
public partial class App : PrismApplication { protected override void RegisterTypes(IContainerRegistry containerRegistry) { //依赖注入 containerRegistry.Register<IMedicineSerivce, MedicineSerivce>(); } }
MVVM使用:
public class MainWindowViewModel : BindableBase { private readonly IDialogService dialog; private readonly IRegionManager regionManager; private readonly IMedicineSerivce medicineSerivce; public MainWindowViewModel(IRegionManager _regionManager, IDialogService dialogService, MedicineSerivce _medicineSerivce) { medicineSerivce = _medicineSerivce; regionManager = _regionManager; dialog = dialogService; } }