//---------------------------------------------------------------------------------------- // patterns & practices - Smart Client Software Factory - Guidance Package // // This file was generated by this guidance package as part of the solution template // // This class contains code that otherwise would be repeated in every presenter when using the M-V-P pattern. // It includes a reference to a generic view and a reference to the WorkItem it belongs. // It also provides virtual methods to work with the controlled view // // For more information see: // ms-help://MS.VSCC.v80/MS.VSIPCC.v80/ms.practices.scsf.2007may/SCSF/html/03-01-010-How_to_Create_Smart_Client_Solutions.htm // // Latest version of this Guidance Package: http://go.microsoft.com/fwlink/?LinkId=62182 //---------------------------------------------------------------------------------------- using Microsoft.Practices.CompositeUI; using System; using Microsoft.Practices.CompositeUI.SmartParts; namespace DialogBox.Infrastructure.Interface { public abstract class Presenter<TView> : IDisposable { private TView _view; private WorkItem _workItem; public TView View { get { return _view; } set { _view = value; OnViewSet(); } } [ServiceDependency] public WorkItem WorkItem { get { return _workItem; } set { _workItem = value; } } protected virtual void CloseView() { Services.IWorkspaceLocatorService locator = WorkItem.Services.Get<Services.IWorkspaceLocatorService>(); IWorkspace wks = locator.FindContainingWorkspace(WorkItem, View); if (wks != null) wks.Close(View); } public virtual void OnViewReady() { } protected virtual void OnViewSet() { } ~Presenter() { Dispose(false); } /// <summary> /// See <see cref="System.IDisposable.Dispose"/> for more information. /// </summary> public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// <summary> /// Called when the object is being disposed or finalized. /// </summary> /// <param name="disposing">True when the object is being disposed (and therefore can /// access managed members); false when the object is being finalized without first /// having been disposed (and therefore can only touch unmanaged members).</param> protected virtual void Dispose(bool disposing) { if (disposing) { if (_workItem != null) _workItem.Items.Remove(this); } } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)