Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are AppDomains are created for every request?

In ASP.NET 3.5 (with IIS6), are AppDomains are created for every request? I know that all applications have their own AppDomain under w3wp.exe, but how exactly does the whole AppDomain work?

I was arguing today with a colleague who was trying to convince me that if an ASP.NET application has a static object (or Singleton class), that this object will be shared among all the requests. I think this is false. Am I right? How do I convince my colleague?

Thanks!

like image 234
Martin Avatar asked Jan 17 '09 05:01

Martin


People also ask

How does an app domain get created?

AppDomains are created by the . Net runtime when a managed application is initialised. When you start ABC. EXE, it gets an application domain.

How many application domain can be used in single process?

Process A runs managed code with one application domain while Process B runs managed code has three application domains. Note that Process C which runs unmanaged code has no application domain. Code and data are safely isolated using the boundary provided by the AppDomain.

What is AppDomain used for?

An application domain (commonly called AppDomains) is a logical unit of isolation that enables you to execute multiple applications within the same process while at the same time ensuring that crash of a particular application domain doesn't affect the functioning of another application domain.

What is AppDomain in .NET core?

The AppDomain class implements a set of events that enable applications to respond when an assembly is loaded, when an application domain will be unloaded, or when an unhandled exception is thrown. For more information on using application domains, see Application Domains.


1 Answers

I'm sorry to say that your colleague is correct. Within an ASP.NET application, each application configured as such in IIS runs within its own AppDomain, which is the scope of a singleton object. So a singleton in App1 is available to all requests to App1 (and could become a concurrency if not handled carefully), but requests in App2 would not be able to access the singleton in App1.

Threading and Pooling in the HTTP Pipeline
(source: microsoft.com)

This diagram from MSDN Magazine helps show how each application is isolated in its own AppDomain. While the diagram shows an IIS5 worker process (aspnet_wp.exe), an IIS6 worker process would be similar for applications configured to run in the same Application Pool.

like image 86
John Clayton Avatar answered Oct 02 '22 10:10

John Clayton