public class StatisticsViewPresenter { private IStatisticsView view; private Statistics statsModel; public StatisticsViewPresenter(IStatisticsView view, Statistics statsModel) { this.view = view; this.statsModel = statsModel; } }
I do not use events (but I am ready if this can solve my problem), so my View classes look like this:
public class StatisticsForm : Form, IStatisticsView { public StatisticsForm() { InitializeComponent(); } [Inject] public StatisticsViewPresenter Presenter { private get; set; } }
FROM
kernel.Bind<StatisticsPresenter>().ToSelf().InSingletonScope(); kernel.Bind<IStatisticsView>().To<StatisticsForm>(); kernel.Get<IStatisticsView>();
it creates a form, creates a presenter, and then enters the presenter in the Presenter property. All peachy. (Except the presenter with a singleton region is any thought on a better way to do this? Maybe just manually enter the presenter in the Presenter property view inside the presenter constructor: this.view.Presenter = this).
But if I go to StatisticsForm in StatisticsUserControl and drag it to my MainForm, it will not be nested in MainForm from Ninject, it will just be new'd from the constructor. Here I see three solutions:
1) Do not use UserControls and just use one giant form that implements these multiple views (eww);
2) Injecting UserControls into my form and lose support for Designer;
3) Your decision! :)
c # dependency-injection ninject user-controls windows-forms-designer
Sam pearson
source share