This project is read-only.

what is a configuration factory

Think of a configuration as a detailed information that your application needs to run effectively. Rapid makes use of a configuration factory concept for you to pre-configure your your application with rapid during load time. The configuration factory is initialized once in an application life time.

The configuration factories are the configuration part of our Rapid Entity Framework. There are two Configuration factories as of writing, the WebConfigurationFactory (Used for web projects) and the Configurationfactory used for Console Project.

To use this ORM framework efficiently, we need to set up the following:
  • Create a new project under visual studio, reference the PersistentManager.dll, this DLL file gives us all that we need to do with the ORM framework.
  • Create an app.config or web.cofig (If you are building a web application). An example is :

<add name="MSAccess" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};User Id=;Password="/>

SQL Server
		<add name="SQLServer" connectionString="Data Source=.\SQLEXPRESS;Initial 
                               Catalog=PersistTest;Integrated Security=True; MultipleActiveResultSets=True"/>

                //Note* MultipleActiveResultSets=True. This attribute is suported by SQL Server 2005, 
                //and it is mandatory in Rapid Entity, because it allows you to open multiple datareaders within   a single connection

<add name="MySql" connectionString="server=localhost;user id=root;password=password;database=test;persist security info=True"/>

<add name="Oracle" connectionString="Data Source=localhost;User ID=userId;Password=password;Unicode=True" />

Console and SQL Server 2005

string connectionString = ConfigurationManager.ConnectionStrings["SQLServer"].ConnectionString;
ConfigurationFactory factory = ConfigurationFactory .GetInstance(connectionString);
factory.ProviderDialect = ProviderDialect.SqlProvider;

  • Create a global.asax file or if you are a lover of HttpModule, create a class that implements IHttpModule, and you can override the specific methods and events (Like BeginRequest, EndRequest, Init and Dispose) in the http module. But for the sake of simplicity, I will be using the global.asax file. The following code describes what you need to do when setting up your Persistent Framework in the global.asax file:

Web and Access Database
void Application_Start(object sender, EventArgs e) 
// Code that runs on application startup
string connectionString = ConfigurationManager.ConnectionStrings["MSAccess"].ConnectionString;

connectionString = string.Format(connectionString, Server.MapPath(@"~\App_Data\ demodatabase.mdb"));


WebConfigurationFactory.GetInstance().ProviderDialect =     ProviderDialect.OleDbProvider;

In the code fragment above, we override the void Application_Start event handler of the global.asax file. What this gives to us, is the abilities to handle application start event in, this code fragment is called once in an application life time, until the web server is shutdown. The following is the pseudocode that explains what is going on over there:
  • Get the connection string from the configuration file and store it in the connectionString variable. The connection string is named MSAccess, in this example.
  • For ASP.NET user’s the Server.MapPath gets the full file path of the location of the access database. I will be tempted to get the file location for a standalone application. We are reading the full file path into the connectionString variable, since we are using Microsoft Access; we need to know the location of our database.
  • The Persistent Framework has a Factory class, called WebConfigurationFactory which implements the IConfiguration interface, the reason behind this will be mentioned later durring the Persistent Framework implementations detail. The WebConfigurationFactory takes the responsibilites of initiliising and destroying connection to the underlying database. It’s a configuration helper that manages the lifetime of a connection to the database. Let us come back to how we will write the code against the ORM framework.
  • WebConfigurationFactory.GetInstance(connectionString); This method sets the connectionString into the internals of the Rapid Entity Framework for database connection purposes. This method creates a single instance of the WebConfigurationFactory class, that is used across the entire application. This . Standalone application developers should’nt worry because, In a standalone context, you will be using the ConfigurationFactory class.
  • After loading the connection string into the Rapid Framework Runtime, we need to tell the framework which Dialect to use in processing the SQL mapping to object. The WebConfigurationFactory.GetInstance().ProviderDialect = ProviderDialect.OleDbProvider; The code snippet above, tells the framework to use the OleDbProvider as the provider for communication between the Rapid Framework runtime and the database. As of writing, I have been able to create two providers, the SqlServerProvider and the OleDbProvider they both implements the IDatabaseProvider. The discussions of this providers is not in this section.
  • We have successfully setup our Rapid Persistent Framework for OORM use. Now we need to start using it to map relational to object.

Last edited Jun 13, 2009 at 8:17 PM by ahmedsalako, version 5


No comments yet.