10.4. Building a Provider-Based Feature

Now that you have seen the rationale and architecture behind provider-based features, walking through the basic steps of writing a simple provider-based feature along with a custom provider will help you tie together the previous concepts to the provider support classes in both the 2.0 and 3.5 Frameworks. In this section, you will walk through the steps of building a provider-based feature, as shown in Figure 10-1.

Figure 10-1. Figure 10-1

Because the intent of this section is to concentrate on creating a provider-based feature, the feature used for the sample will define and implement only one method that simply requests a string from its default provider. The sample provider base class definition is:

C#

using System;
using System.Configuration.Provider;

namespace SampleFeature
{
    public abstract class SampleFeatureProvider : ProviderBase
    {
        //Properties
        public abstract string Color { get; }
        public abstract string Food { get; }

        //Methods
        public abstract string GetMeAString(string andPutThisOnTheEndOfIt);
    }
}

VB.NET

Imports Microsoft.VisualBasic
Imports System
Imports System.Configuration.Provider
Namespace SampleFeature Public MustInherit Class SampleFeatureProvider Inherits ProviderBase 'Properties Public MustOverride ReadOnly Property Color() As String Public MustOverride ReadOnly Property Food() As String 'Methods Public MustOverride ...

Get Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.