我有一系列类,每个类根据它们的角色有几个依赖项。这些依赖项被注入到构造函数中。一个例子是:
public class UserViewModel
{
//...
public UserViewModel(IDataService dataService,
INotificationService notificationService,
IDialogService dialogService,
INavigationService navigationService)
{
this.DataService = dataService;
this.NotificationService = notificationService;
this.DialogService = dialogService;
this.NavigationService = navigationService;
}
}
如您所见,有几个参数需要设置。我可以编写如下界面:
public interface IInteractionService
{
public INotificationService NotificationService { get; set; }
public IDialogService DialogService { get; set; }
public INavigationService { get; set; }
}
并将注入的 InteractionService 实现一次性传递给 UserViewModel 的构造函数:
public UserViewModel(IDataService dataService,
IInteractionService interactionService) {}
并像这样使用它:
this.InteractionService.NotificationService.Publish(message);
在设计模式/原则方面使用具有接口属性的交互接口是否有任何问题?或者有没有更好的方法来看待它?
感谢您的任何建议...