Click here to Skip to main content
15,896,318 members
Articles / Web Development / HTML

Leveraging .NET Components and IDE Integration: UI AOP in an MVC use case

Rate me:
Please Sign up or sign in to vote.
4.99/5 (125 votes)
28 Jun 200598 min read 354.5K   835   384  
An in-depth exploration of the features and the power of .NET Component Model architecture, its integration with the IDE at design-time and the possiblities it opens through extensions at run-time.
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Web;
using System.Web.UI;

using Mvc.Components;
using Mvc.Components.Controller;
using Mvc.Components.Design;
using Mvc.Components.Model;

namespace PubsMvc
{
	[ToolboxItem(true)]
	public class PublisherController : BaseController
	{
		#region Ctor & Designer stuff

		private System.ComponentModel.IContainer components;

		public PublisherController(IContainer container)
		{
			container.Add(this);
			InitializeComponent();
		}

		public PublisherController()
		{
			InitializeComponent();
		}

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.publisher = new PubsMvc.PublisherModel(this);
			this.bookTitle = new PubsMvc.TitleModel(this);
			// 
			// publisher
			// 
			this.publisher.ConnectionString = "";
			this.publisher.ModelName = "Publisher";
			// 
			// bookTitle
			// 
			this.bookTitle.ConnectionString = "";
			this.bookTitle.ModelName = "Title";
			this.bookTitle.PublicationDate = new System.DateTime(((long)(0)));

		}
		#endregion

		#endregion

		#region Methods

		public void LoadTitle(string id)
		{
			bookTitle.ID = id;
			bookTitle.Load();
			RaiseModelChanged(bookTitle);
		}

		public void LoadTitle()
		{
			bookTitle.Load();
			RaiseModelChanged(bookTitle);
		}

		public void DeletePublisher()
		{
			// Could refactor to call a business object that saves the business entity.
			publisher.Delete();
			RaiseModelChanged(publisher);
		}

		public void LoadPublisher()
		{
			// Could refactor to call a business object that saves the business entity.
			publisher.Load();
			RaiseModelChanged(publisher);

		}

		public void SavePublisher()
		{
			// Could refactor to call a business object that saves the business entity.
			publisher.Save();
			RaiseModelChanged(publisher);
		}

		#endregion

		private PubsMvc.PublisherModel publisher;
		private PubsMvc.TitleModel bookTitle;

		#region Public properties

		[Category("MVC")]
		[Bindable(true)]
		[Description("Gets/Sets the connection string of the model.")]
		[RecommendedAsConfigurable(true)]
		public string ConnectionString
		{
			get { return _connection; }
			set 
			{ 
				_connection = value; 
				//Propagate setting to connectable models.
				foreach (IComponent model in Components)
					if (model is IConnectable)
						((IConnectable)model).ConnectionString = value;
			}
		} string _connection;

		#endregion
	}
}

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Argentina Argentina

Comments and Discussions