Delphi's DataModules were a useful programming tool because they provided a centralized place to define data schema and business logic which could then be referenced from multiple locations. Visual Studio .NET, however, encourages the programmer to place DataSets and Adapters on each individual page, resulting in decentralized and possibly redundant business logic. However, it is possible to roll your own DataModule-like components in .NET. Here's how:
Sample Code
using System;
namespace MyNamespace.MyDataModules{
[ Serializable() ] [ System.ComponentModel.ToolboxItem( true ) ] // MyStronglyTypedDataSet is the name of the DataSet class // automatically generated by Visual Studio .NET public class CustomDataSet : MyStronglyTypedDataSet {
// CustomDataSetAdapters is the name of the Component class
// containing all the DataAdapters used to generate, fill,
// and update the DataSet.
private CustomDataSetAdapters _Adapters; private System.ComponentModel.Container components = null; public CustomDataSet( System.ComponentModel.IContainer container ) { container.Add( this ); InitializeComponent(); // Initialize DataSet properties here
_Adapters = new CustomDataSetAdapters( container ); } public CustomDataSet() { // Initialize DataSet properties here
_Adapters = new CustomDataSetAdapters(); } protected override void Dispose( bool disposing ) { if ( disposing ) { if ( components != null ) { components.Dispose(); } } base.Dispose( disposing ); }
// This property exposes the component class containing
// all the DataAdapters used to generate, fill, and update
// the DataSet
public CustomDataSetAdapters Adapters
{
get
return _Adapters;
}
} public void BusinessLogicMethod1() { // Custom business logic here } }}
Remember Me
a@href@title, i, strike, u
Copyright © 2003-2008 Falafel Software Inc.
Subscribe to Falafel Blogs
The opinions expressed herein are Falafel's employees own personal opinions and do not represent Falafel Software's view in any way in case they go bananas!