- Application domains provide a flexible and secure method of isolating running applications that need to be able to communicate with each other.
- Application domains represent a virtual process on a layer between an operating system process and the threads.
- Before .NET days, the choice would be between allowing those instances to share a process (with the resultant risk of a problem in one running instance bringing the whole web site down) or isolating those instances in separate processes (with the associated performance overhead).
- Although processes are great for security reasons, their big disadvantage is in the area of performance.
- The obvious example of this is where a process calls up a COM component, which is an executable and therefore is required to run in its own process.
- The same thing happens in COM when surrogates are used.
- Because processes cannot share any memory, a complex marshaling process must be used to copy data between the processes.
- This results in a very significant performance hit.
- If you need components to work together and do not want that performance hit, you must use DLL-based components and have everything running in the same address space with the associated risk that a badly behaved component will bring everything else down.
- Application domains are designed as a way of separating components without resulting in the performance problems associated with passing data between processes.
- The idea is that any one process is divided into a number of application domains.
- Each application domain roughly corresponds to a single application, and each thread of execution will be running in a particular application domain.
https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5945004e-d119-47d9-b3c1-ec93b3e44625/Untitled
- By introducing a layer between the program and the operating system, it is possible to implement virtual processes or applications known as application domains (app domains).
- An application domain behaves like an operating system process in that it offers a level of isolation between other application domains.
- An app domain has its own virtual memory allocation, and communication between application domains requires distributed communication paradigms, just as it would between two operating system processes.
- Static data is not shared between application domains, so static constructors run for each application domain, and assuming a single thread per application domain, there is no need to synchronize the static data because each application has its own instance of the data.
- Each application domain has its own threads, and just like with an operating system process, threads cannot cross application domain boundaries.
- The point of an application domain is that processes are considered relatively expensive. With application domains, you can avoid this additional expense by running multiple application domains within a single process.
- You can use a single process to host a series of web sites. However, you can isolate the web sites from each other by placing them in their own application domain.