假设一个主窗体有几个菜单项。每个菜单项将显示另一种形式。以下代码是在这种情况下进行依赖注入的好方法吗?
public class MainForm: Form {
private IAboutForm _aboutForm;
private IOptionsForm _optionsForm;
private IDownloadsForm _downloadsForm;
MainForm(IAboutForm aboutForm, IOptionsForm optionsForm, IDownloadsForm downloadsForm) { // add as many form dependencies as required
_aboutForm = aboutForm;
_optionsForm = optionsForm;
_downloadsForm = downloadsForm;
InitializeComponent();
}
private void AboutMenuItem_Click(object sender, System.EventArgs e) {
_aboutForm.ShowDialog(this);
}
private void DownloadsMenuItem_Click(object sender, System.EventArgs e) {
_downloads.Show();
_downloads.BringToFront();
}
}