Skip to content

Microkernel guide&demo for WPF (sdi), Winforms (sdi/mdi/tdi) and Console processes

Notifications You must be signed in to change notification settings

dudinda/MVPTemplate

Repository files navigation

MVP Template

The original repository

  1. Guide
  2. Demo

How to Set Up

  1. Create a presentation layer as a dynamic library. Install the ImageProcessing.Microkernel.EntryPoint from Nuget. Add an implementation of the IStartup interface, create folders for presenters/events/views/viewmodels.
  2. Define a new interface for your main view. It should implement the IView interface.
  3. Create a new presenter for your main view. Inherit it from the BasePresenter<TView>. Create a new domain event and subscribe it to the main presenter with the ISubscriber<TEventArgs> interface.
  4. Create an executing assembly. Reference the presentation library. It can be a console, WPF or WinForms project. Add an implementation of the IStartup interface for the UI Layer components.
  5. In case of WF or WPF, create a base form to handle write/read from another thread or access the aggregator or application controller. Create a property for the application controller. Set it with the AppController.Controller. Using the Controller.IoC property register the ApplicationContext / Application as a singleton then resolve it and bind to the Context property. You can do it once via the null reference check with the private field. Hide the Show with the new syntax then set the MainForm as this. Pass the Context to the Application.Run.
  6. Implement the IMainView interface for your main form. In case of WF/WPF use the Aggregator.Unpublish inside the Dispose/Close call. Hide the generated dispose with the new syntax then replace if a view is a transient, or remove it in the case of a singleton, delegating the disposing call to a DI-container.
  7. Inject the singleton instance of the IEventAggregator into your main form or expose elements to a custom event binder component. Bind the defined domain event.
  8. Register the implemented presentation startup dependecies with the new Startup().Build(builder) inside the UIStartup. Register the main view and its event binder. You can declare the main view as a singleton to inject it to child views and access control properties via the exposer cast.
  9. Inside the Program class use the static state machine to AppLifecycle.Build<UIStartup> and AppLifecycle.Run<MainPresenter>.

How to Develop

  1. Use Run<TPresenter> or Run<TPresenter, TViewModel> to run a presenter. When a View accessed for the first time, a DI - container resolve the view by its interface, decoupling a concrete implementation of a gui framework (WF, WPF, Console) component.
  2. Use PublishFrom<TEventArgs>(object publisher, TEventArgs args) to unicast a message from a view to its presenter.
  3. Use PublishFromAll<TEventArgs>(object publisher, TEventArgs args) to broadcast a message from a view to all presenters subscribed to the TEventArgs. It can also be used to message from a presenter to a presenter if a target presenter have a unique subscriber during the broadcast.
  4. Use Unsubscribe(Type subscriber, object publisher) to unsubcribe a view from its presenter. Can be used during the disposing of a view.

How to Test

  1. Generate or create virtual wrappers around the original components. If a component has a composition with another wrapper, expose its interface as a public property. Extend the original forms with NonUIForms, overriding the write/read methods. Inside a form wrapper create a bridge with a NonUIForm.
  2. Inside a presenter use the original source code, operating with partial substitutes. Expose substitutes as a public property.
  3. Extend the SynchronizationContext, override the Post property. Override the Post inside the aggregator, set the extended SynchronizationContext. Replace the original aggregator with its wrapper. .Result the .ConfigureAwait(false) calls.
  4. Using the fluent interface, build the partial substitutes with the virtual wrappers to operate with the original components by default.
  5. Create a base test, use the static state machine to Build partial substitutes and to Dispose on the [TearDown].
  6. Write a synchronous scenario using partial substitutes. Raise an event from a form wrapper. Use .Receieved() interface to validate arguments and return values.

WFMDI

application window

Fig. 1 - The main MDI - form and child transient forms and the singleton form. The main menu also shows the message from the singleton form.



WFSDI

application window

Fig. 2 - The main form and child SDI transient forms and the singleton form. The main menu also shows the message from the singleton form.



WFTDI

application window

Fig. 3 - The main form and child TDI transient tabs and the singleton tab. The main menu also shows the message from the singleton tab. To close the tab focus the "Send Message" button and press the Del key.



WPFSDI

application window

Fig. 4 - The main window and child transient windows and the singleton window. The main window also shows the message from the singleton window.



Console

application window

Fig. 5 - The console window is started with the main command and then the singleton command is switched to a foreground thread.



About

Microkernel guide&demo for WPF (sdi), Winforms (sdi/mdi/tdi) and Console processes

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages