Application Domain in .Net ,A must know topic for every .net developer
If you are a web developer and you do not know about the application domain then leave your all work and start reading this article from start to end. Also if your going for an Interview then you must be aware of App Domain.
Let us know what actually Application Domain is? So from its basic definition it is " used to isolate applications from one another ". So if we have two different applications are deployed at same machine then it works as a logical wall between them. So it may be redefined as the "CLR equivalent of an operation system’s process ".
Refer the following pic, you will be clear more on the Application Domain:
If we look at MSDN then will found the following details:
Historically, process boundaries have been used to isolate applications running on the same computer. Each application is loaded into a separate process, which isolates the application from other applications running on the same computer.
Now you may wonder why we need to isolate the applications?
Answer is applications are isolated because memory addresses are process-relative; a memory pointer passed from one process to another cannot be used in any meaningful way in the target process. In addition, you cannot make direct calls between two processes. Instead, you must use proxies, which provide a level of indirection.
Isolating applications is also important for application security. For example, you can run controls from several Web applications in a single browser process in such a way that the controls cannot access each other's data and resources.
Managed code must be passed through a verification process before it can be run (unless the administrator has granted permission to skip the verification). The verification process determines whether the code can attempt to access invalid memory addresses or perform some other action that could cause the process in which it is running to fail to operate properly. Code that passes the verification test is said to be type-safe. The ability to verify code as type-safe enables the common language runtime to provide as great a level of isolation as the process boundary, at a much lower performance cost.
So if we go in to more deeper to this topic then we have lot to explore and gain, Lets have the benefits of using app domain and what are the mai benefits and why should we use app domains. Go through following lines :
Application domains provide a more secure and versatile unit of processing that the common language runtime can use to provide isolation between applications. You can run several application domains in a single process with the same level of isolation that would exist in separate processes, but without incurring the additional overhead of making cross-process calls or switching between processes. The ability to run multiple applications within a single process dramatically increases server scalability.
The isolation provided by application domains has the following benefits:
Beside the above mentioned point please note that :
Let us know what actually Application Domain is? So from its basic definition it is " used to isolate applications from one another ". So if we have two different applications are deployed at same machine then it works as a logical wall between them. So it may be redefined as the "CLR equivalent of an operation system’s process ".
Refer the following pic, you will be clear more on the Application Domain:
If we look at MSDN then will found the following details:
Historically, process boundaries have been used to isolate applications running on the same computer. Each application is loaded into a separate process, which isolates the application from other applications running on the same computer.
Now you may wonder why we need to isolate the applications?
Answer is applications are isolated because memory addresses are process-relative; a memory pointer passed from one process to another cannot be used in any meaningful way in the target process. In addition, you cannot make direct calls between two processes. Instead, you must use proxies, which provide a level of indirection.
Isolating applications is also important for application security. For example, you can run controls from several Web applications in a single browser process in such a way that the controls cannot access each other's data and resources.
Managed code must be passed through a verification process before it can be run (unless the administrator has granted permission to skip the verification). The verification process determines whether the code can attempt to access invalid memory addresses or perform some other action that could cause the process in which it is running to fail to operate properly. Code that passes the verification test is said to be type-safe. The ability to verify code as type-safe enables the common language runtime to provide as great a level of isolation as the process boundary, at a much lower performance cost.
So if we go in to more deeper to this topic then we have lot to explore and gain, Lets have the benefits of using app domain and what are the mai benefits and why should we use app domains. Go through following lines :
Application domains provide a more secure and versatile unit of processing that the common language runtime can use to provide isolation between applications. You can run several application domains in a single process with the same level of isolation that would exist in separate processes, but without incurring the additional overhead of making cross-process calls or switching between processes. The ability to run multiple applications within a single process dramatically increases server scalability.
The isolation provided by application domains has the following benefits:
- Faults in one application cannot affect other applications. Because type-safe code cannot cause memory faults, using application domains ensures that code running in one domain cannot affect other applications in the process.
- Individual applications can be stopped without stopping the entire process. Using application domains enables you to unload the code running in a single application.
- You cannot unload individual assemblies or types. Only a complete domain can be unloaded.
- Code running in one application cannot directly access code or resources from another application. The common language runtime enforces this isolation by preventing direct calls between objects in different application domains. Objects that pass between domains are either copied or accessed by proxy. If the object is copied, the call to the object is local. That is, both the caller and the object being referenced are in the same application domain. If the object is accessed through a proxy, the call to the object is remote. In this case, the caller and the object being referenced are in different application domains. Cross-domain calls use the same remote call infrastructure as calls between two processes or between two machines. As such, the metadata for the object being referenced must be available to both application domains to allow the method call to be JIT-compiled properly. If the calling domain does not have access to the metadata for the object being called, the compilation might fail with an exception of type System.IO.FileNotFound. The mechanism for determining how objects can be accessed across domains is determined by the object.
- The behavior of code is scoped by the application in which it runs. In other words, the application domain provides configuration settings such as application version policies, the location of any remote assemblies it accesses, and information about where to locate assemblies that are loaded into the domain.
- Permissions granted to code can be controlled by the application domain in which the code is running.
Beside the above mentioned point please note that :
* Direct communication cannot be acheived across application domains.Application domains can still talk to each other by passing objects via marshalling by value (unbound objects), marshalling by reference through a proxy (AppDomain-bound objects). There is a third type of object called a context-bound object which can be marshalled by reference across domains and also within the context of its own application domain. Because of the verifiable type-safety of managed code, the CLR can provide fault isolation between domains at a much lower cost than an operating system process can. The static type verification used for isolation does not require the same process switches or hardware ring transitions that an operating system process requires.
Enjoy your coding and post your comments/ suggestions. Will post another topic which will help you all in your coding and most important in your Interviews :) .
SOURCE : MSDN
Happy Coding
Thanks & Regards
Dharmendra Kumar
Enjoy your coding and post your comments/ suggestions. Will post another topic which will help you all in your coding and most important in your Interviews :) .
SOURCE : MSDN
Happy Coding
Thanks & Regards
Dharmendra Kumar
good job man..
ReplyDelete