I'm using Ninject to handle my dependencies.
My ApplicationPresenter is responsible to dispatch the user calls to features throughout the application, hence the need to inject multiple factories at once, thus the container itself. It handles an MDI GUI.
- Is there a better approach?
- Is it okay to make it so?
ApplicationPresenter
public class ApplicationPresenter
: Presenter<IApplicationView>
, IApplicationPresenter {
public ApplicationPresenter(IApplicationView view, IKernel dependencies)
: base(view) {
Dependencies = dependencies;
View.Connect += OnConnect;
View.ManageInquiries += OnManageInquiries;
}
private static readonly IKernel Dependencies;
}
The ApplicationPresenter is responsible for orchestrating the system's feature in the MDI window such as:
- User authentication
- Managing inquiries...
I have an AuthenticationPresenter and an InquiryManagementPresenter which shall both be called from the ApplicationPresenter like so:
User clicks on...
public class ApplicationPresenter : ... {
// See ctor for event subscription...
private void OnConnect() {
AuthenticationPresenter authentication =
Dependencies.Get<IAuthenticationPresenter>();
authentication.ShowView();
}
private void OnManageInquiries() {
InquiriesManagementPresenter inquiriesManagement =
Dependencies.Get<IInquiriesManagementPresenter>();
inquiriesManagement.ShowView();
}
}
And within the InquiriesManagementPresenter, I have dependencies on other presenters as:
- NewInquiryPresenter
- EditInquiryPresenter
- CancelInquiryPresenter
- ApproveInquiryPresenter...
Ninject modules
public class ApplicationModule : NinjectModule {
public void Load() {
Bind<IApplicationPresenter>().To<ApplicationPresenter>().InSingletonScope();
Bind<IApplicationView>().To<ApplicationForm>();
}
}
public class AuthenticationModule : NinjectModule {
public void Load() {
Bind<IMembershipService>().To<MembershipService>();
Bind<IAuthenticationPresenter>().To<AuthenticationPresenter>().InSingletonScope();
Bind<IAuthenticationView>().To<AuthenticationForm>();
Bind<ICredentials>().To<Credentials>().InSingletonScope();
Bind<IUser>().To<User>().InSingletonScope();
Bind<IDatabaseInstance>().To<DatabaseInstance>().InSingletonScope();
Bind<IDatabaseUser>().To<DatabaseUser>().InSingletonScope();
}
}
public class InquiryManagementModule : NinjectModule {
public void Load() {
Bind<INewInquiryPresenter>().To<NewInquiryPresenter>().InSingletonScope();
Bind<INewInquiryView>().To<NewInquiryForm>();
Bind<IEditInquiryPresenter>().To<EditInquiryPresenter>().InSingletonScope();
Bind<IEditInquiryView>().To<EditInquiryForm>();
Bind<IInquiryRepository>().To<InquiryRepository>();
// ...
}
}
So, I find it simpler to pass the Ninject's IKernel from from a presenter to another for those that require multiple functionality like the InquiryManagementPresenter or the ApplicationPresenter.
So still, is it this okay or is there another much better way to achieve this?