Architecture Overview

N-Tier Windows Forms Framework

Summary

This document describes the architecture for the NTier Framework.

Description

The diagram below describes how the major components of the NTier framework fit together between each tier:

UI tier

The UI tier of the NTier framework provides controls, data binding helpers, validation notification icons, caption rendering, form actions and design time tools. The UI tier is responsible for coordinating create, retrieve, update, delete, data binding, caption rendering and notification rendering operations between the entity layer and the user.

Major classes:

Class Description
NForm / NUserControl These base classes are generally inherited by forms and user controls in the application. The base classes provide data binding helper methods and several IExtenderProvider implementations that add properties and behaviour to child controls at design time and run time (see below for a list of IExtenderProvider components).
NBindingSource An IExtenderProvider that provides the 'BindingMember' property for each bindable control of a form/user control. This object holds the form data source object and is responsible for coordinating .net data binding between entity properties and controls.
NotificationProvider An IExtenderProvider that renders validation notifications from the entity layer as icons in the UI. This component plugs into the FullBindingMembers and FullBindingMembersChanged members of NBindingSource and control events to perform property validation as the data is entered.
LabelCaptionProvider An IExtenderProvider that places Label objects next to controls dynamically and sizes/renders property descriptions.
Control Extenders TextBoxExtender, for example, provides additional functionality to TextBox without the need to subclass from TextBox. TextBoxExtender (for example) provides mappings for ReadOnly, MaxLength, DecimalPlaces meta-data data binding.
NDataGridView Provides cell level notification icons and custom column types to facilitate data binding scenarios provided by NTier.
For a complete list of UI classes provided by NTier, see the NTier API Reference.

No control inheritance

A key design principal in NTier is that controls need not be inherited to provide NTier functionality. Instead, IExtenderProviders, ControlExtenders and extension methods provide new functionality to existing System.Windows.Forms controls.

NDataGridView, NForm and NUserControl are exceptions to this rule as it wasn't possible to provide the required functionality with control extenders alone.

NForm / NUserControl IExtenderProviders

NForm and NUserControl are generally inherited by forms and user controls in the application. It's safe (and recommended) to switch from System.Windows.Forms.Form and System.Windows.Forms.UserControl base classes to NForm and NUserControl without unintentionally changing existing application behaviour.

The IExtenderProvider interface is provided by .net to allow helper classes attached to forms and user controls to provide additional properties on child controls, without the need to provide specific base classes for those controls. NForm and NUserControl provide the following useful IExtenderProvider components for their descendents:

IExtenderProvider service Description
BindingSource Provides the 'BindingMember' property and coordinates data binding for the controls.
NotificationProvider Render notification icons on data bound controls.
LabelCaptionProvider Renders control captions from entity property descriptions.
ControlActionsExtenderProvider Attaches the 'Actions' property to buttons and menu items to provide Form Actions functionality.
ComponentExtenderEarlyInstallProvider Initializes component extenders early so that events can be hooked at the right time.
ButtonActionHookedCheckProvider Provides compile time checks to ensure each button and menu item click/actions are configured.
ContextMenuUnusedCompileTimeCheckProvider Provides compile time checks to ensure all ContextMenu/ContextMenuStrip objects are assigned.
DesignerActionExtenderProvider Provides the ability to apply the [SmartTag] attribute to control / control extender properties to show additional properties in the control smart tag list at design time.

Entity tier

The Entity tier of the NTier framework provides entity Object Relational Mapping (ORM), entity querying, validation, meta-data and entity WCF service functionality.

Major classes / interfaces:

Class Description
IEntity IEntity is the interface implemented by every entity, including for entities that have no base class.
NEntity A convenience base class for entities that provide saving/saved events and surfaces useful members of IEntity. Also, much of the code generation required to make the entity proxy class is reduced.
IEntitySet Contains a root entity, it's aggregate and other related entities that have been added or loaded and provides the following services:

  • Entity add/modify/update/delete operations are tracked in the IEntitySet which stores the changes as a 'unit of work' that will be applied when IEntitySet.SaveChanges is called.
  • The root of the aggregate may be accessed via the Root property.
  • An IEntitySet may be cloned in it's entirety, along with it's unit of work. Note that individual entities may not be cloned in isolation.
  • An IEntitySet may be serialized across the wire in xml format using the entity WCF service.
  • The entities of one IEntitySet may be merged with another IEntitySet. This is used by IEntityDataSynchronizer to apply saved data back to in-memory IEntitySet objects.
Typically there's one IEntitySet per unit of work. For example, there is one IEntitySet per edit of data via a form so that making or discarding changes in a form doesn't affect the same data in another form or search screen.
IEntityCollection / NEntityCollection An entity collection provides an active view over a set of collections that match a filter. The entity collection is used to return entities from IEntityAccessor, and to bind data to the UI.
EntityDescriptor Describes the attribute reflection meta-data from an entity type.
IEntityDataSynchroniser Provides synchronization between IEntitySets as data is loaded from and saved to the underlying data store. This is how entity properties in a grid's are updated automatically when a form's data is saved.
IEntityAccessor Provides the ability to load/save entities in a database or over a web service. See Entity Accessor Framework for more information.
For a complete list of NTier entity support classes provided by NTier, see the NTier API Reference.

Data tier

The Data tier of the NTier framework provides entity select/update/insert/delete sql code generation, database schema manipulation APIs, database schema upgrader, and the ability to load/save entities from a database.

Major classes / interfaces:

Class Description
DbProvider Provides an abstraction of the underlying database provider.
IDbConnectionProvider / DbConnectionScope Provides a strategy for returning IDbConnection objects. The underlying strategy may return new connection objects on each access to facilitate connection pooling, or return the same connection to maintain a single connection with the database.
DbEntityAccessor Provides the ability to load and save entities in a database.
ReflectEntityRelationalMapping Describes the mapping between the entity model and the relational model using attributes applied to the entity type.
EntitySqlCommandBuilder Builds the sql commands required to eager or lazy load an aggregate of entities of a particular type. When navigating eager loaded relationships, multiple sql statements may need to be built with numerous inner joins statements as appropriate.
For a complete list of NTier data access support classes provided by NTier, see the NTier API Reference.

Back to NTier Documentation