Dynamic Application Configuration

Applications may require dynamic runtime configuration to allow for contact with a service provider, such as an email or database server, the determination of available system and network resources, or the changes to the user environment in order to meet with deployment requirements or user preferences. The .NET Framework includes support for dynamic properties, which can be configured at runtime without requiring a recompilation of the base application.

Using Dynamic Properties

Dynamic properties are managed at runtime by the System.Configuration.AppSettingsReader class. The Visual Studio .NET IDE allows you to define dynamic properties for your application.

graphics/tip_icon.gif

You can only use dynamic properties within applications that create an executable (EXE) file. Applications that create DLL files may not use dynamic properties.


You can configure a dynamic property for a form by performing the following steps:

  1. Open an instance of Visual Studio .NET and create a new Visual Basic .NET Windows Application project, including a form.

  2. In the form's Properties window, click the plus sign (+) next to the DynamicProperties entry.

  3. Click in the Advanced section and click the build () button to open the Dynamic Properties dialog box (see Figure 15.1).

    Figure 15.1. The Dynamic Properties dialog box displaying the selection of the Text and ShowInTaskbar properties as dynamic properties.

    graphics/15fig01.jpg

  4. Select the properties that will be configured for dynamic runtime evaluation and then click OK to close the dialog box.

  5. After you save the form and run the application within the IDE, the app.config file will be created and displayed in the Solution Explorer window. Editing this XML file allows for the manipulation of the dynamic properties used each time the application is run.

  6. After you compile the application, the < appname >.exe.config file will be created in the application's bin directory. This XML file may be edited to alter the configuration settings used at runtime.

Some .NET components create dynamic properties by default. If you drag an Access database from the Server Explorer to a Windows form, .NET will automatically include a dynamic property entry for the OleDbConnection component. If you later remove a property from the dynamic properties list, the key and last value for that property will remain in the configuration file. It is important to remember to remove any password or development-only values from the file before deploying your application.

graphics/alert_icon.gif

All the dynamic properties on forms, controls, and components in a project use the same configuration file, named < appname >.exe.config .


Application configuration files will generally override settings in the machine configuration file ( machine.config ), unless the machine configuration file can direct that the application configuration file not be used.

Using the .NET Framework Configuration Tool

When you load the .NET Framework on a server, the .NET Framework Configuration tool is included (see Figure 15.2). This Microsoft Management Console (MMC) snap-in may be located by selecting Start, Programs, Administrative Tools, Microsoft .NET Framework Configuration.

Figure 15.2. The .NET Framework Configuration tool running in the MMC shell.

graphics/15fig02.jpg

Using this tool, it is possible to manage the following items:

  • The contents of the Global Assembly Cache.

  • Machinewide configured assemblies, which map from one assembly version to another. Figure 15.3 shows an example of this.

    Figure 15.3. A configured assembly, mapping version 1.0.3300.0 to the new 2.0.0.0 version.

    graphics/15fig03.jpg

  • Remoting channels, which allow for communication with objects on remote systems.

  • Security policy settings.

  • Application settings, which allow each application to have its own remoting and configured assembly rules.

graphics/note_icon.gif

The .NET Framework Configuration snap-in does not perform validation when specifying a new configured assembly mapping. If you attempt to load a nonexistent assembly, you will get a Just-In-Time (JIT) debugging error.




Developing and Implementing WindowsR-based Applications with Visual BasicR. NET and Visual StudioR. NET Exam CramT 2 (Exam 70-306)
Developing and Implementing WindowsR-based Applications with Visual BasicR. NET and Visual StudioR. NET Exam CramT 2 (Exam 70-306)
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 188

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net