The use of ActiveRecord development process I think we all thought, configuration so much if not ctrl+c/ctrl+v still have to remember in their head, inevitable miscellaneous?
Whether you're using a collection object like Hashtable,arraylist or using a Web.config class configuration or using an XML file for a separate configuration, you always have to remember or let your hard drive remember the ActiveRecord configuration string. Easy for You ctrl+c/ Ctrl + V.
[Working with collection objects]
Hashtable properties = new Hashtable();
properties.Add("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
properties.Add("hibernate.dialect", "NHibernate.Dialect.MsSql2000Dialect");
properties.Ad("hibernate.connection.provider","NHibernate.Connection.DriverConnectionProvider");
properties.Add("hibernate.connection.connection_string", "Data Source=.;
Initial Catalog=test;Integrated Security=SSPI");
InPlaceConfigurationSource source = new InPlaceConfigurationSource();
source.Add(typeof(ActiveRecordBase), properties);
[Using XML configuration section]
<activerecord>
<config>
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
<add key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>
<add key="hibernate.connection.connection_string"
value="Data Source=.;Initial Catalog=test;Integrated Security=SSPI" />
</config>
</activerecord>
Using the above two ways is not very troublesome, last week when I was doing projects in the company thought to write a general method to deal with ActiveRecord, personally feel very good, write down the idea of everyone to share.
Solution Analysis
In response to this situation, my idea is to configure the method of encapsulation, by passing the database name and project Entity Data assembly to the method, the implementation of the method to encapsulate the method to deal with, as follows:
Because castle support is not only a database of MSSQL, MYSQL,DB2 .... Also supported, since it is a common method, it is necessary to consider this. Here I adopt the factory pattern, define abstract classes and abstract methods, let the derived class implement him, and invoke different implementation class methods as needed through the factory:
1public abstract class Initialize
2{
3 public abstract void ActiveRecordInit(string dataBase,string model);
4}