Como: Configurar um domínio do aplicativoHow to: Configure an Application Domain

Você pode fornecer o Common Language Runtime com informações de configuração para um novo domínio de aplicativo usando a classe AppDomainSetup.You can provide the common language runtime with configuration information for a new application domain using the AppDomainSetup class. Ao criar seus próprios domínios de aplicativo, a propriedade mais importante é ApplicationBase.When creating your own application domains, the most important property is ApplicationBase. As outras propriedades AppDomainSetup são usadas principalmente por hosts de runtime para configurar um domínio de aplicativo específico.The other AppDomainSetup properties are used mainly by runtime hosts to configure a particular application domain.

A propriedade ApplicationBase define o diretório raiz do aplicativo.The ApplicationBase property defines the root directory of the application. Quando o runtime precisar atender a uma solicitação de tipo, ele investigará em busca do assembly que contém o tipo no diretório especificado pela propriedade ApplicationBase.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.

Observação

Um novo domínio de aplicativo herdará apenas a propriedade ApplicationBase do criador.A new application domain inherits only the ApplicationBase property of the creator.

O exemplo a seguir cria uma instância da classe AppDomainSetup, usa essa classe para criar um novo domínio de aplicativo, escreve as informações no console e então descarrega o domínio de aplicativo.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.

ExemploExample

using namespace System;
using namespace System::Reflection;

ref class AppDomain4
{
public:
    static void Main()
    {
        // Create application domain setup information.
        AppDomainSetup^ domaininfo = gcnew AppDomainSetup();
        domaininfo->ApplicationBase = "f:\\work\\development\\latest";

        // Create the application domain.
        AppDomain^ domain = AppDomain::CreateDomain("MyDomain", nullptr, domaininfo);

        // Write application domain information to the console.
        Console::WriteLine("Host domain: " + AppDomain::CurrentDomain->FriendlyName);
        Console::WriteLine("child domain: " + domain->FriendlyName);
        Console::WriteLine("Application base is: " + domain->SetupInformation->ApplicationBase);

        // Unload the application domain.
        AppDomain::Unload(domain);
    }
};

int main()
{
    AppDomain4::Main();
}
using System;
using System.Reflection;

class AppDomain4
{
    public static void Main()
    {
        // Create application domain setup information.
        AppDomainSetup domaininfo = new AppDomainSetup();
        domaininfo.ApplicationBase = "f:\\work\\development\\latest";

        // Create the application domain.
        AppDomain domain = AppDomain.CreateDomain("MyDomain", null, domaininfo);

        // Write application domain information to the console.
        Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
        Console.WriteLine("child domain: " + domain.FriendlyName);
        Console.WriteLine("Application base is: " + domain.SetupInformation.ApplicationBase);

        // Unload the application domain.
        AppDomain.Unload(domain);
    }
}
Imports System.Reflection

Class AppDomain4
    Public Shared Sub Main()
        ' Create application domain setup information.
        Dim domaininfo As new AppDomainSetup()
        domaininfo.ApplicationBase = "f:\work\development\latest"

        ' Create the application domain.
        Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing, domaininfo)

        ' Write application domain information to the console.
        Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName)
        Console.WriteLine("child domain: " + domain.FriendlyName)
        Console.WriteLine("Application base is: " + domain.SetupInformation.ApplicationBase)

        ' Unload the application domain.
        AppDomain.Unload(domain)
    End Sub
End Class

Consulte tambémSee also