Subscribe

RSS Feed (xml)

Creating an Application Domain

The simplest overload of the CreateDomain method takes a single string argument specifying a human-readable name (friendly name) for the new application domain. Other overloads allow you to specify evidence and configuration settings for the new application domain. Evidence is specified using a System.Security.Policy.Evidence object; in future we will discuss the effects of providing evidence when you create an application domain. Configuration settings are specified using a System.AppDomainSetup object.
The AppDomainSetup class is a container of configuration information for an application domain. Table 3.1 lists some of the properties of the AppDomainSetup class that you will use most often when creating application domains. These properties are accessible after creation through members of the AppDomain object, and some are modifiable at run time; refer to the .NET Frameworks SDK documentation on the AppDomain class for a comprehensive discussion.
Table 3.1: Commonly Used AppDomainSetup Properties
Property
Description
ApplicationBase
The directory where the CLR will look during probing to resolve private assemblies. Probing is discussed in recipe 3.5. Effectively, ApplicationBase is the root directory for the executing application. By default, this is the directory containing the assembly. Readable after creation using the AppDomain.BaseDirectory property.
ConfigurationFile
The name of the configuration file used by code loaded into the application domain. Readable after creation using the AppDomain.GetData method with the key APP_CONFIG_FILE.
DisallowPublisherPolicy
Controls whether the publisher policy section of the application configuration file is taken into consideration when determining which version of a strong named assembly to bind to. Publisher policy is discussed in recipe 3.5.
PrivateBinPath
A semicolon-separated list of directories that the runtime uses when probing for private assemblies. These directories are relative to the directory specified in ApplicationBase. Readable after application domain creation using the AppDomain.RelativeSearchPath property. Modifiable at run time using the AppendPrivatePath and ClearPrivatePath methods.
The following example demonstrates the creation and configuration of an application domain.
// Instantiate an AppDomainSetup object.
AppDomainSetup setupInfo = new AppDomainSetup();

// Configure the application domain setup information.
setupInfo.ApplicationBase = @"C:\MyRootDirectory";
setupInfo.ConfigurationFile = "MyApp.config";
setupInfo.PrivateBinPath = "bin;plugins;external";

// Create a new application domain passing null as the evidence 
// argument. Remember to save a reference to the new AppDomain as 
// this cannot be retrieved any other way.
AppDomain newDomain = AppDomain.CreateDomain(
    "My New AppDomain",
    new System.Security.Policy.Evidence(),
    setupInfo);

No comments:

Post a Comment

Archives

LocalsAdda.com-Variety In Web World

Fun Mail - Fun in the Mail