Castle study NOTE 2: framework structure and configuration

Source: Internet
Author: User
Tags log4net

Reference NetworkArticleAnd learning from existing projects to familiarize yourself with the framework structure and configuration.

The structure of existing projects and case projects is a little different, but the general structure is similar, including:

Domain: System field. All Database entity objects and data carriers must be used at other layers.

Persistence: the persistence layer that stores persistent data to the database, including interfaces and mapperdao)

Service: the service layer. All business methods used by the system call the persistence layer, including implement and interface)

Web: Page layer (end-to-user interaction)

Common: System Public layer, including public methods and Classes

 

Configuration:

1. Configure the Web. config file for Castle. You need to put web. config in a web applicationProgramIn the root directory of, Castle will automatically read from web. config.

<! -- New Value Under <configuration> node -->
< Configsections >
< Section Name = "Castle" Type = "Castle. Windsor. configuration. appdomain. castlesectionhandler, Castle. Windsor" />
</ Configsections >

< Castle >
<! -- Extends Castle and combines ibatisnet as a plug-in with Castle -->
< Include Uri = "File: // config/facilities. config" />
<! -- Tell Castel which interface is implemented by which class -->
< Include Uri = "File: // config/services. config" />
<! -- Sqlmapdao at The Persistence Layer -->
< Include Uri = "File: // config/persistence/sample. config" />
</ Castle >

<System. Web>
<! --
<Pages/>
<Httphandlers>... <Httpmodules>... ... Many configurations
-->
</System. Web>

 

2. configuration of facilities. config file

< Configuration >
< Facilities >
< Facility ID = "Logging" Type = "Castle. Facilities. Logging. loggingfacility, Castle. Facilities. Logging" Loggingapi = "Log4net" Configfile = "Log4net. config" />
<! -- Extended ibatisnet for Castle -->
< Facility ID = "Ibatis" Type = "Castle. Facilities. ibatisnetintegration. ibatisnetfacility, Castle. Facilities. ibatisnetintegration"   >
< Sqlmap ID = "Sqlserversqlmap" Config = "Sqlmap. config"   />
<! -- Multiple data sources are supported, but the corresponding sqlmap. config file and properties. config file are required. The new isqlmapper must be declared in persistence, and the constructor must be modified to enable Castle to be instantiated through IOC.
<Sqlmap id = "sqlmaplocal" Config = "sqlmaplocal. config"/>
-->
</ Facility >
< Facility ID = "Biztiminghandle" Type = "Castle. Facilities. biztiminghandle. biztiminghandlefacility, Castle. Facilities. biztiminghandle"   />
<! -- Supports business-layer transactions and extends transaction processing for Castle -->
< Facility ID = "Transaction" Type = "Castle. Facilities. automatictransactionmanagement. transactionfacility, Castle. Facilities. automatictransactionmanagement"   /> </ Facilities >
</ Configuration >

 

In this way, Castle can automatically manage ibatisnet and run ibatisnet automatically when ibatisnet is required.

3. Configure the service. config file

< Configuration >
< Components >
< Component ID = "Yoursolution. aabiz" Service = "Yoursolution. Service. iaabiz, yoursolution. Service" Type = "Yoursolution. Service. aabiz, yoursolution. Service" />
< Component ID = "Yoursolution. bbbiz" Service = "Yoursolution. Service. ibbbiz, yoursolution. Service" Type = "Yoursolution. Service. bbbiz, yoursolution. Service" />
<! -- Others -->
</ Components >
</ Configuration >

 

It can be found that the iaabiz class is implemented by the aabiz class, and Castle will automatically assemble it. That is, when the request needs to call the method in the iaabiz interface, the aabiz class will be automatically instantiated, and call the corresponding method.

4. configuration of sqlmap. config in the configuration file ibatisnet

< Sqlmapconfig
Xmlns = "Http://ibatis.apache.org/dataMapper"
Xmlns: xsi = "Http://www.w3.org/2001/XMLSchema-instance" >
<! -- Path of the providers. config file, the Project Name of the Web Application -->
< Properties Embedded = "Yoursolution. Web. properties. config, yoursolution. Web"   />
< Settings >
< Setting Usestatementnamespaces = "False" />
</ Settings >
< Providers Resource = "Config/providers. config" />
< Database >
<! -- The parameters are set in properties. config. -->
< Provider Name = "$ {Provider }" />
< Datasource Name = "Documentsystem" Connectionstring = "$ {Connectionstring }" />
</ Database >
< Sqlmaps >
< Sqlmap Embedded = "$ {Root} cntypegenmap. XML, $ {Assembly }"   />
< Sqlmap Embedded = "$ {Root} cntypemap. XML, $ {Assembly }"   />
<! -- Other map... -->
</ Sqlmaps >
</ Sqlmapconfig >

 

The above sets the sqlmap that ibatisnet performs database operations on entities.

5. Configure the Dao. config file

Why? Why can't I find Dao. config or Dao configuration in the project?

Refer to the Dao. config configuration in the article:

< Daoconfig Xmlns = "Http://ibatis.apache.org/dataAccess" Xmlns: xsi = "Http://www.w3.org/2001/XMLSchema-instance" >
< Context ID = "Sqlmapdao" Default = "True" >
< Daosessionhandler ID = "Sqlmap" >
< Property Name = "Resource" Value = "Sqlmap. config" />
</ Daosessionhandler >
< Daofactory >
< Dao Interface = "ATS. Persistence. interface. iemployeesdao, ATS. Persistence" Implementation = "ATS. Persistence. mapperdao. employeessqlmapdao, ATS. Persistence" />
</ Daofactory >
</ Context >
</ Daoconfig >

 

It mainly sets the <daofactory> node and the implementation class corresponding to the DaO runtime interface, that is, iemployeesdao is implemented by employeessqlmapdao.

 

Main reference: http://hi.baidu.com/tlq_1983/blog/item/28b4aef5edfd9920bc3109c1.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.