Common applications and best practices for application domains in .NET?

What are some guidelines and guidelines for creating new application domains in an application?

Also, what are the common uses and examples of using multiple application domains in an application?

+6
c # applicationdomain
source share
3 answers

The most common scenario I've seen is the ability to provide extensibility with a different security model than the main program.

Loading a plugin into a separate AppDomain allows two things:

  • You can implement a more limited security model.
  • You can prevent the plugin from dropping the application if it does not work

Another nice use of AppDomains is to download and verify the build. Running this in a separate AppDomain allows you to collect information (or run code) from a separate assembly, and then unload the entire assembly from your process space. If you download an assembly directly, it cannot be unloaded. This is also useful if you want to "upgrade" the type to a new version at run time (that is, load the remote assembly and reload it later).

+7
source share

It is recommended to create a new domain if you need to place 3-party components in the application that are unreliable or you do not trust them (for example, plug-ins) or want to unload them.

+5
source share

A typical example is for cases related to plugins. This not only allows you to unload the DLL if necessary, but also gives you better security control over what the plugin allows you to do.

Also, if you create temporary assemblies (code generations) that you want to unload again, this is a good way to do this. (LCG allows you to implement only one method if you want to implement the full class that you need to pass to the "real" assembly).

+3
source share

All Articles