Provider model design pattern

My older post about this title was published here. In this post, I’ll try to share my interest in some of the design patterns that were presented in one of the mkdot.net sessions.

Provider model design pattern

Maybe I’m a little late with this post but I want to emphasize the use of the provider model introduced in ASP.NET 2.0 and its implementations within Membership, Roles, Sitemap, and other providers. The starting point for teaching yourself about Provider Toolkit is here and also additional information about building your provider model.
In this post, I’ll show my homework implementing a small Membership provider following the steps described here and here.
 
A provider is a software module that provides a uniform interface between a service and a data source. Providers abstract physical storage media, in much the same way that device drivers abstract physical hardware devices. Because virtually all ASP.NET 2.0 state-management services are provider-based, storing session state or membership state in an Oracle database rather than a Microsoft SQL Server database is as simple as plugging in Oracle session state and membership providers. Code outside the provider layer needn't be modified, and a simple configuration change, accomplished declaratively through Web.config, connects the relevant services to the Oracle providers.

My Homework

First of all setting the web.config sections as described in the picture below is needed. We define a section group name (green rectangle), then define section name (blue rectangle) and type. Then these section definitions need to be included in the <system.web> section.


In the next figure is presented the class diagram of the MyProvider class library. As you can see there are several classes with certain behavior


Class explanation:

  1. ProviderBase.cs –  is the base class common to all providers.
  2. MembershipProvider.cs – is base class (contract), which is used to implement the desired behaviors for the Membership API.
  3. SqlMembershipProvider.cs – is our implementation of the Membership APIs for a Microsoft SQL Server database. Also we can implement it for Oracle or MySQL database systems or it can be implemented with XML or flat files. All of our Data Access Layer (DAL) and Business Logic Layer (BLL) code is put into this class.
  4. Membership.cs – is class that defines routines for our API such as CreateUser, Validate, GetAllUsers, IsActive etc. When calling routines on this class internally it will always forward those calls to an instance of the MembershipProvider.
  5. Provider.cs - is the basic definition of the feature’s provider class. This class contains information about entries in the <providers> section for MembershipVane's configuration section.
  6. MembershipConfigurationHandler.cs - reads the XML configuration information from the web.config file.

Sources:

http://msdn.microsoft.com/en-us/library/ms972319.aspx
http://msdn.microsoft.com/en-us/library/ms972370.aspx
http://msdn.microsoft.com/en-us/library/aa479030.aspx?ppud=4
http://www.agdstudio.com/DesignPatterns/ProviderModel/ASPNET2.0ProviderModel.pdf

Download:

Comments