Posted by: Cirilo Meggiolaro | 10/25/2008

Tip of the day #11 – Isolating your assemblies in application domains

Developers have worked for a long time with session objects in web applications but how does .NET CLR manage the sessions in ASP.NET? The answer is: application domains.

We can define an application domain as a logical container that isolates an application instance creating boundaries for security, data access and the flexibility to unload a single application domain and all assemblies inside it without affecting other application domains within the same process.

Imagine a user accessing a .NET web site. The user has his application domain and the session objects will not be shared between users. It happens because a new application domain has been created when the user accesses that application (starting a new session). In this web example multiple application domains are within a single aspnet worker process (aspnet_wp.exe).

The ASP.NET application is a good example but you can use application domains in different scenarios. They are recommended to isolate critical assemblies, long running processes, large assemblies that might cause performance related issues or bring down an entire process. In the first application hiccup you may want to unload the application domain without affect any other part of your system.

How to…

A simple example that demonstrates the .NET AppDomain object in action and three basic tasks: create application domain, execute assembly and unload the application domain.

/// Creates a new domain
AppDomain myAppDomain = AppDomain.CreateDomain(“MyAppDomainName”);

/// Executes an assembly

/// Unloads an application domain

To get full details about application domains and how to set security properties, click here!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: