メイン フォームにいくつかのメニュー項目があるとします。メニュー項目ごとに別のフォームが表示されます。次のコードは、このシナリオで依存性注入を行う良い方法ですか?
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();
}
}