Castle. ActiveRecord Initialization Configuration supplement and configuration encapsulation Solution

Source: Internet
Author: User

I wrote an article about AR configuration a few days ago. I wrote it after I made a small instance for a friend who just learned AR. I used IConfigurationSource, activeRecord is in the web. as configured in config, ActiveRecord can be written elsewhere or dynamically configured. For example, it can be configured using XML or Hashtable. next I will briefly introduce how to configure it.

1. Use XML configuration to obtain configuration information through XmlConfigurationSource. For detailed configuration, see the following xml data.

1 <? Xml version = "1.0" encoding = "UTF-8"?>
2 <activerecord>
3 <config>
4 <add
5 key = "hibernate. connection. driver_class" value = "nhib.pdf. Driver. SqlClientDriver"/>
6 <add
7 key = "hibernate. dialect" value = "NHibernate. Dialect. MsSql2000Dialect"/>
8 <add
9 key = "hibernate. connection. provider" value = "nhib.pdf. Connection. DriverConnectionProvider"/>
10 <add
11 key = "hibernate. connection. connection_string" value = "Data Source =.; Initial Catalog = test; Integrated Security = SSPI"/>
12 </config>
13 </activerecord>
14

XmlConfigurationSource source = new XmlConfigurationSource ("../appconfig. xml ");
2. Use Hashtable to implement configuration. Use InPlaceConfigurationSource to obtain configuration information.

1 Hashtable properties = new Hashtable ();
2properties. Add ("hibernate. connection. driver_class", "nhib.pdf. Driver. SqlClientDriver ");
3properties. Add ("hibernate. dialect", "nhibect. Dialect. MsSql2000Dialect ");
4properties. Add ("hibernate. connection. provider", "nhib.pdf. Connection. DriverConnectionProvider ");
5properties. Add ("hibernate. connection. connection_string", "Data Source =.; Initial Catalog = test; Integrated Security = SSPI ");
6 InPlaceConfigurationSource source = new InPlaceConfigurationSource ();
7source. Add (typeof (ActiveRecordBase), properties );

The above two methods can be used to configure ActiveRecord. I prefer the second method, Hashtable, in general applications, there is actually no difference. I wrote a general method in the company a few days ago to reflect the gap. We should all know that modifying strings is easier than modifying XML, take the above "Data Source = .; initial Catalog = test; Integrated Security = SSPI "database connection string, if you write the ActiveRecord configuration on the Web. in the config or XML file, when you create a program, you need to configure a web. config node or add an XML file. Here I think of writing a general method to solve this problem, when I need to program, I only need to input the database name and the Entity Data assembly of the program. Other work is called to the encapsulated method for processing.

For more information about solutions for ActiveRecord configuration encapsulation, click the following article to connect

ActiveRecord configuration encapsulation Solution

Http://www.cnblogs.com/beniao/archive/2007/12/01/979087.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.