Introduction
In the part 1 we learned the basic idea of ASP. net provider model. in this Part I will explain the overall architecture of ASP. net built-in providers. specifically we will be dissecting the membership provider.
The base classes for membership providers
Have a look at figure below:
As you can see, the base class for all the providers is providerbase. the providerbase class resides in system. configuration. provider namespace from system. configuration namespace. this class is marked as abstract and it provides template for further inheritance chain. one of the important method of this class is initialize (). this method is used to read the configuration information of the provider from web. config File and initialize the provider.
The membershipprovider class resides in system. web. security namespace. this class is inherited from the providerbase class and adds membership specific members (especially user creation and management related members) to itself. this class is also marked as abstract.
Finally, sqlmembership class from system. Web. Security inherits the membershipprovider class. This is a concrete class that implements properties and methods from providerbase and membershipprovider specifically for SQL Server databases.
Other provider classes
Similar class hierarchy can be seen for other providers such as SQL role provider and SQL profile provider.
For example, the inheritance chain for SQL role provider is as follows:
Providerbase-> roleprovider-> sqlroleprovider
And the inheritance chain for SQL profile provider is:
Providerbase-> settingsprovider-> profileprovider-> sqlprofileprovider
Abstract classes or interfaces
In. NET 2.0 I see some changes in the design guidelines by Microsoft. in the previous versions. net they used to rely more on interfaces to provide template for framework classes. for example, in ADO. net 1.x all the data provider classes implement certain common interfaces (idbconnection, idbcommand etc .). though ADO. NET 2.0 continues to implement these interfaces It is mainly for the sake of backward compatibility. they have opted for abstract classes in ADO. NET 2.0. the same goes for provider classes. instead of providing template via interfaces they have opted for abstract classes. the possible reasons that I can see are:
- Abstract classes can provide some implementation which interfaces can not.
- Interfaces are unalterable once implemented as that will break all the classes that are already implementing the interface.
- With abstract classes the base class can be evolved without disturbing the child classes that already inherit from it.
Summary
In this article we looked into the structure of built-in ASP. NET providers. In the next article we will develop a custom membership provider using our knowledge of part 1 and 2.