Below is the final of our three new Sueetie Wiki docs for today. Patterns and Origins: The Sueetie Data Provider Model.
____________________
The data provider model is common throughout the applications that comprise Sueetie. Here we'll cover the Sueetie Framework's particular flavor of that provider model.
Sueetie Data Provider - Patterns
Each of the applications in Sueetie uses a Data Provider, and in most cases several providers to support multiple data sources. This is the case with BlogEngine.NET, which uses an XML Provider to manage blog data as well as a SQL Provider to manage user data simultaneously. BlogEngine.NET is blazingly fast, so besides having a robust provider implementation, the raw speed of BE.NET was another reason to pattern the Sueetie.Core Data Provider model after BE.NET.
Here is the layout of the Sueetie.Core Class Library and the location of the various Data Provider classes. Pertinent items include the Base and SQL Provider classes in the Providers folder, the Container objects populated by the provider and passed to the application, and the Action Class or Proxy which does the passing. In our example the sole class currently serving as the Action Class is "SueetieUsers.cs." All Action Classes are located in the Sueetie.Core root directory.
Below is the LoadProviders() method of the SueetieDataProvider base class and shows how the Sueetie.Core providers are loaded from the Sueetie.Config file as a SueetieConfiguration Generic List and converted to the appropriate Type.
The providers are loaded from Sueetie.config in SueetieConfiguration using LINQ-to-XML. That method is shown below.
private void PopulateProviders()
{
var providers = from provider in configXML.Descendants("Provider")
select new SueetieProvider
{
ConnectionString = (string)provider.Element("connectionString"),
Name = (string)provider.Element("name"),
Function = (string)provider.Element("function"),
ProviderType = (string)provider.Element("type")
};
SueetieProviders = providers.ToList();
}
Because the Sueetie.Config file is shared across multiple applications, the actual connection string is entered into the .config file. This avoids managing the provider's connection string in each of the site applications using Sueetie.Core.
Here is an example of using the Data Provider in the SueetieUsers.cs Action Class. We'll create the Provider with LoadProvider() and passing our query to the Provider Base and SQL classes.
public static void CreateSueetieUser(SueetieUser sueetieUser)
{
SueetieDataProvider _provider = SueetieDataProvider.LoadProvider();
_provider.CreateSueetieUser(sueetieUser);
}
Sueetie Data Provider - Origins
I wanted to pattern the Sueetie.Core Provider model after BlogEngine.NET as much as possible for performance reasons and simply because I wanted to spend more time in one of my very favorite applications. Main differences in Sueetie.Core implementation are loading the provider through SueetieConfiguration instead of a web.config ProviderSection and breaking out the Provider code from the Proxy class file.
For example, BlogEngine.NET uses a BlogService.cs Class as proxy where the Provider method to load all providers is also found.
public static Post SelectPost(Guid id)
{
LoadProviders();
return _provider.SelectPost(id);
}
I separated the provider to make the Sueetie Framework more extensible by enabling multiple proxy classes to share a single provider.
Sueetie.Core Patterns and Origins Documents: