Today, I finally started the EnterpriseLibrary process. I want to read and learn. Here I want to thank TerryLee's predecessors. After reading your article, I have gained a lot of knowledge, making it easier for me to enter the status. As he has just been familiar with this plug-in, no matter which project configuration file is definitely the starting point of our research, first of all, we need to look at some of the Enterprise Library's practices on the configuration file.
After the EnterpriseLibrary is installed, the configuration file in VS is opened with the Enterprise Library Configration by default. config changes are opened in the source file format. Then, an error occurs when you use the change: "try to read or write the protected memory. It usually indicates that other memory has been damaged ." If you know anything, please let me know. Thank you! In TerryLee's article, we found a Configuration Application Block, but this node is not available in the current version or version 2.0. There is only tracing aion Sources, and this node contains two subnodes: file Configuration Source and System Configuration Source. The default value is System Configuration Source, which is Web. config or App. config configuration file.
By default, we can use the SystemConfigurationSource class, which inherits from the IConfigurationSource interface. GetSection () and other methods can be used to operate on the file. It is worth mentioning that the configured File Reading is cached in EnterpriseLibrary, of course, after changing the configuration file, we should notify the system to remove the cache and re-read and cache it. In fact, we don't need to know how it is cached, as long as we tell him that we have changed the configuration file. Because I still don't quite understand the truth, I can't explain the whole mechanism here. In fact, we basically don't care about it in the default configuration, for example, we can directly use DataProviderFactory in the Data Access Application Block to create an abstract Database instance, while EnterpriseLibrary has encapsulated the entire process.
If we want to use FileConfigurationSource, and of course we want to use this class to read the information in the configuration file, I am interested in this, just as a few days ago, someone asked me why I don't like Session, this cannot be said, but it may have something to do with me. Don't you like it, don't you don't need it or don't use it. We're all lazy people. Is that simple? Too many! In my limited resources, it seems that I want to put the configuration in other files, there must be Web. config and App. the config file exists, and the file name and Provider of other configuration files are configured. The following uses the connection string as an example to see how to read the Data. config file. If you set this option to the default value, you can directly use DataProviderFactory. If not, you need to use the code to create it:
FileConfigurationSource source = new FileConfigurationSource ("Data. config ");
DatabaseProviderFactory dbFactory = new DatabaseProviderFactory (source );
Database db = dbFactory. Create ("ConnectionStringName ");
In this way, we get a Database instance to complete our operations. I am not very familiar with this winter and winter, but I think I will become a good friend with him, because I am preparing to use this for the next project. Although it is not a very large project, this will consolidate my knowledge, haha! If you have any errors, please correct them. Thank you!