.Net Runtime Library for Delphi
How to: Configure an Application Domain

You can provide the common language runtime with configuration information for a new application domain using the AppDomainSetup interface. When creating your own application domains, the most important property is ApplicationBase. The other AppDomainSetup properties are used mainly by runtime hosts to configure a particular application domain. The ApplicationBase property defines the root directory of the application. When the runtime needs to satisfy a type request, it probes for the assembly containing the type in the directory specified by the ApplicationBase property.

The following example creates an instance of the AppDomainSetup class, uses this class to create a new application domain, writes the information to console, and then unloads the application domain.


program AppDomain; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, CNClrLib.Host, CNClrLib.Core; var Console: _Console; domain: TClrAppDomain; domaininfo: _AppDomainSetup; begin try Console := CoConsole.CreateInstance; // Create application domain setup information. domaininfo := CoAppDomainSetup.CreateInstance; domaininfo.ApplicationBase := 'C:\Temp\AppDomainDemo\EXE\Win32\Debug'; // Create the application domain. domain := TClrAppDomain.CreateDomain('MyDomain', nil, domaininfo); // Write application domain information to the console. Console.WriteLine_14('Host domain: ' + TClrAppDomain.GetCurrentDomain.FriendlyName); Console.WriteLine_14('child domain: ' + domain.FriendlyName); Console.WriteLine_14('Application base is: ' + domain.DefaultInterface.SetupInformation.ApplicationBase); //NB: The DefaultInterface is the AppDomain Inteface. The TClrAppDomain is //a wrapper of the _AppDomain Dispatch Interface // Unload the application domain. TClrAppDomain.Unload(domain); Console.ReadKey; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. //Output //Host domain: DefaultDomain //child domain: MyDomain //Application base is: C:\Temp\AppDomainDemo\EXE\Win32\Debug