1. To create a provider we first have to create a public abstract class that defines our contract. This class must implement the System.Configuration.ProviderBase abstract class and it should contain the definition of methods and properties used as the "contract" of our provider
using System.Configuration.Provider;
namespace ConsoleApplication1.ProviderSample
{
public abstract class StringResourceProvider:ProviderBase
{
public abstract string GetString(string id);
public abstract void AddString(string id ,string value);
}
}
2. add the actual implementations of the provider
- XmlStringResourceProvider Implementation
- SqlStringResourceProvider Implementattion
3. create the service that will use the StringResourceProvider. It's is coupled to the contract definition of our provider and not to its implementations, so it knows what to ask for but no actually how or where will it be done.
StringResourceService service = new StringResourceService();
service.GetString("key1");
service.AddString("key2","value2");