Lightweight. NET Object Search Service and AOP development framework Netop. Core source code explanation (2) -- configuration, aopnetop. core
Put "Object Search Service", the Core part of Netop. Core, and introduce the configuration of the application system.
The configuration of an application system is indispensable unless you are a hard-coded stubborn person.
I have also seen some application systems have dozens or even hundreds of nodes in the deleettings through the key-value method provided by the system, which is unsightly, let alone rational.
To develop an application framework, configuration is generally indispensable. For example, log4net has its own configuration, so it won't allow you to set dozens of entries in the deleettings.
The development configuration is very simple. Let's talk about it later.
In the. NET application, the configuration information is stored as an XML document. The WEB application is a Web. config file, and the executable file is *. exe. config (copied and renamed by app. config during compilation ).
In NET, the Configuration file information is read by the processor class of the System. Configuration. IConfigurationSectionHandler interface. The interface has only one method:
Object Create (Object parent, object configContext, XmlNode section );
In Netop. Core, the Configuration processor class is Netop. Core. Configuration. ConfigurationHandler.
After the configuration processor class is implemented, the XML Information of the node is obtained and parsed to read the relevant content. In Netop. Core, ConfigurationHandler handed the job to Netop. Core. Configuration. AppConfigurationManager.
You can see the actual configuration information:
<ConfigSections>
<Section name = "Netop. Application" type = "Netop. Core. Configuration. ConfigurationHandler, Netop. Core"/>
<Section name = "log4net" type = "log4net. Config. Log4NetConfigurationSectionHandler, log4net"/>
</ConfigSections>
The configuration processor class of log4net is log4net. Config. Log4NetConfigurationSectionHandler.
The Configuration processor class of Netop. Core is Netop. Core. Configuration. ConfigurationHandler, And the node name is Netop. Application. Then, let's look at the Netop. Application Section:
<Netop. Application type = "Netop. Core. Configuration. AppConfigurationManager, Netop. Core">
<Application. ObjectLocator>
<DefaultAppObjectLocatorService> Netop. Core. LocatorService. DefaultAppObjectLocatorService, Netop. Core </DefaultAppObjectLocatorService>
<ObjectServiceAgentName> AppObjectService </ObjectServiceAgentName>
<AspectAgentName> AppAspect </AspectAgentName>
</Application. ObjectLocator>
<Application. Log>
<LogCategory> Netop. Core. Log. Log4Net, Netop. Core </LogCategory>
<LogParameter> Log </LogParameter>
</Application. Log>
<Application. Agent>
<Agent name = "AppObjectService" type = "Netop. Core. Configuration. FileAgentConfiguration, Netop. Core">
<File> Service. xml </File>
</Agent>
<Agent name = "AppAspect" type = "Netop. Core. Configuration. FileAgentConfiguration, Netop. Core">
<File> Aspect. xml </File>
</Agent>
<Agent name = "AppEntity" type = "Netop. Core. Configuration. FileAgentConfiguration, Netop. Core">
<File> Entity. xml </File>
</Agent>
</Application. Agent>
</Netop. Application>
<Netop. Application type = "Netop. Core. Configuration. AppConfigurationManager, Netop. Core"> the value of type is AppConfigurationManager.
In Netop. in Core, there is a class Netop. core. configuration. settingConfiguration implements read operations similar to "<LogCategory> Netop. core. log. log4Net, Netop. core </LogCategory>.
For SettingConfiguration, Netop. Core has a default node:
<Netop. Application type = "Netop. Core. Configuration. AppConfigurationManager, Netop. Core">
......
<Application. Settings>
......
</Application. Settings>
</Netop. Application>
Add a project in Application. Settings, for example, <Host> smtp.sohu.com </Host>.
The value is Netop. Core. Configuration. AppConfiguration. Current. ApplicationSettingsConfig. GetKeyValue ("Host") and smtp.sohu.com.
You can also add a Section yourself, for example:
<Application. SmtpServer>
<Host> smtp.sohu.com </Host>
<RequriedAuthenticate> true </RequriedAuthenticate>
......
</Application. SmtpServer>
The value is Netop. Core. Configuration. AppConfiguration. Current. getdeleettingconfiguration ("Application. SmtpServer"). GetKeyValue ("Host") and smtp.sohu.com.
In Netop. Core, there is also a proxy Configuration. The proxy Configuration class can be used in a straight way as long as the Netop. Core. Configuration. IConfigurationAgent interface is implemented. The IConfigurationAgent is as follows:
Public interface IConfigurationAgent
{
Void Initialize (XmlNode xml );
AgentConfigurationInfo GetConfigurationInfo ();
}
Netop. Core has implemented an XML file proxy Configuration class: Netop. Core. Configuration. FileAgentConfiguration.
For configuration information:
<Netop. Application type = "Netop. Core. Configuration. AppConfigurationManager, Netop. Core">
<Application. ObjectLocator>
<DefaultAppObjectLocatorService> Netop. Core. LocatorService. DefaultAppObjectLocatorService, Netop. Core </DefaultAppObjectLocatorService>
<ObjectServiceAgentName> AppObjectService </ObjectServiceAgentName>
<AspectAgentName> AppAspect </AspectAgentName>
</Application. ObjectLocator>
<Application. Log>
<LogCategory> Netop. Core. Log. Log4Net, Netop. Core </LogCategory>
<LogParameter> Log </LogParameter>
</Application. Log>
<Application. Agent>
<Agent name = "AppObjectService" type = "Netop. Core. Configuration. FileAgentConfiguration, Netop. Core">
<File> Service. xml </File>
</Agent>
<Agent name = "AppAspect" type = "Netop. Core. Configuration. FileAgentConfiguration, Netop. Core">
<File> Aspect. xml </File>
</Agent>
<Agent name = "AppEntity" type = "Netop. Core. Configuration. FileAgentConfiguration, Netop. Core">
<File> Entity. xml </File>
</Agent>
</Application. Agent>
</Netop. Application>
The <Application. Agent> node contains the proxy configuration information:
<Agent name = "AppObjectService" type = "Netop. Core. Configuration. FileAgentConfiguration, Netop. Core">
<File> Service. xml </File>
</Agent>
Name indicates the proxy configuration name, type indicates the proxy configuration class, and File indicates the File path.
Program usage:
Object p = null;
AppConfiguration. Current. GetAgentData ("AppObjectService", out p); // return the xml Information of the Service. XML file.
Of course, the proxy configuration name AppObjectService is in contact with <ObjectServiceAgentName> AppObjectService </ObjectServiceAgentName>. If you are interested, you can refer to the content of ObjectServiceConfigurationManager.
What Should developers do if they want to add nodes in Netop. Application (not of the aforementioned type) on their own?
AppConfigurationManager has a method: XmlNode GetData (string key). After the call, you can parse the XML Information (call AppConfiguration. Current. GetData ("node name") to return XmlNode ).
This is the configuration service of Netop. Core.
Of course, you can also directly use the configuration processor class of the NET system to process configuration information, such:
System. Configuration. NameValueSectionHandler <! -- Return the information in the configuration section in the form of NameValue key value/pair -->
System. Configuration. DictionarySectionHandler <! -- Return the information in the configuration section in the form of a Dictionary key-value pair -->
System. Configuration. SingleTagSectionHandler <! -- Infrastructure. Process the configuration sections in the. config file represented by a single XML tag. -->
Lightweight. NET Object Search Service and AOP development framework source code Netop. Core3.5: http://download.csdn.NET/detail/tom_cat_xie_jxdy/9837303
Lightweight. NET Object Search Service and AOP development framework test source code: http://download.csdn.Net/detail/tom_cat_xie_jxdy/9837278
Netop. Core -- lightweight. NET object Lookup service and AOP development framework documentation: http://download.csdn.net/detail/tom_cat_xie_jxdy/9838212