Recupero di informazioni di installazione da un dominio applicazione
Ogni istanza di un dominio applicazione è costituita da proprietà e da informazioni AppDomainSetup. È possibile recuperare le informazioni di installazione da un dominio applicazione tramite la classe System.AppDomain. In tale classe sono disponibili svariati membri che consentono di recuperare informazioni di configurazione relative a un dominio applicazione.
Per ottenere le informazioni di installazione passate al dominio nella fase di creazione, è inoltre possibile eseguire una query nell'oggetto AppDomainSetup e cercare il dominio applicazione.
L'esempio seguente consente di creare un nuovo dominio applicazione e di stampare nella console svariati valori relativi ai membri.
Imports System
Imports System.Reflection
Class AppDomain3
Public Shared Sub Main()
' Create the new application domain.
Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing)
' Output to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName)
Console.WriteLine("New domain: " + domain.FriendlyName)
Console.WriteLine("Application base is: " + domain.BaseDirectory)
Console.WriteLine("Relative search path is: " + domain.RelativeSearchPath)
Console.WriteLine("Shadow copy files is set to: " + domain.ShadowCopyFiles)
AppDomain.Unload(domain)
End Sub
End Class
using System;
using System.Reflection;
class AppDomain3
{
public static void Main()
{
// Create the new application domain.
AppDomain domain = AppDomain.CreateDomain("MyDomain", null);
// Output to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("New domain: " + domain.FriendlyName);
Console.WriteLine("Application base is: " + domain.BaseDirectory);
Console.WriteLine("Relative search path is: " + domain.RelativeSearchPath);
Console.WriteLine("Shadow copy files is set to: " + domain.ShadowCopyFiles);
AppDomain.Unload(domain);
}
}
using namespace System;
using namespace System::Reflection;
ref class AppDomain3
{
public:
static void Main()
{
// Create the new application domain.
AppDomain^ domain = AppDomain::CreateDomain("MyDomain", nullptr);
// Output to the console.
Console::WriteLine("Host domain: " + AppDomain::CurrentDomain->FriendlyName);
Console::WriteLine("New domain: " + domain->FriendlyName);
Console::WriteLine("Application base is: " + domain->BaseDirectory);
Console::WriteLine("Relative search path is: " + domain->RelativeSearchPath);
Console::WriteLine("Shadow copy files is set to: " + domain->ShadowCopyFiles);
AppDomain::Unload(domain);
}
};
int main()
{
AppDomain3::Main();
}
L'esempio seguente consente di impostare e recuperare le informazioni di installazione per un dominio applicazione. Si noti che le informazioni di configurazione vengono ricevute da AppDomain.SetupInformation.ApplicationBase.
Imports System
Imports System.Reflection
Class AppDomain5
Public Shared Sub Main()
' Application domain setup information.
Dim domaininfo As New AppDomainSetup()
domaininfo.ApplicationBase = "f:\work\development\latest"
domaininfo.ConfigurationFile = "f:\work\development\latest\appdomain5.exe.config"
' Creates the application domain.
Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing, domaininfo)
' Write the application domain information to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName)
Console.WriteLine("Child domain: " + domain.FriendlyName)
Console.WriteLine()
Console.WriteLine("Application base is: " + domain.SetupInformation.ApplicationBase)
Console.WriteLine("Configuration file is: " + domain.SetupInformation.ConfigurationFile)
' Unloads the application domain.
AppDomain.Unload(domain)
End Sub
End Class
using System;
using System.Reflection;
class AppDomain5
{
public static void Main()
{
// Application domain setup information.
AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = "f:\\work\\development\\latest";
domaininfo.ConfigurationFile = "f:\\work\\development\\latest\\appdomain5.exe.config";
// Creates the application domain.
AppDomain domain = AppDomain.CreateDomain("MyDomain", null, domaininfo);
// Write the application domain information to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("Child domain: " + domain.FriendlyName);
Console.WriteLine();
Console.WriteLine("Application base is: " + domain.SetupInformation.ApplicationBase);
Console.WriteLine("Configuration file is: " + domain.SetupInformation.ConfigurationFile);
// Unloads the application domain.
AppDomain.Unload(domain);
}
}
using namespace System;
using namespace System::Reflection;
ref class AppDomain5
{
public:
static void Main()
{
// Application domain setup information.
AppDomainSetup^ domaininfo = gcnew AppDomainSetup();
domaininfo->ApplicationBase = "f:\\work\\development\\latest";
domaininfo->ConfigurationFile = "f:\\work\\development\\latest\\appdomain5.exe.config";
// Creates the application domain.
AppDomain^ domain = AppDomain::CreateDomain("MyDomain", nullptr, domaininfo);
// Write the application domain information to the console.
Console::WriteLine("Host domain: " + AppDomain::CurrentDomain->FriendlyName);
Console::WriteLine("Child domain: " + domain->FriendlyName);
Console::WriteLine();
Console::WriteLine("Application base is: " + domain->SetupInformation->ApplicationBase);
Console::WriteLine("Configuration file is: " + domain->SetupInformation->ConfigurationFile);
// Unloads the application domain.
AppDomain::Unload(domain);
}
};
int main()
{
AppDomain5::Main();
}
Vedere anche
Concetti
Cenni preliminari sull'hosting
Programmazione con i domini applicazione