Using appdomains to isolate plugins is essentially using remoting. My
approach has been to use a single appdomain for all plugins wherever
possible and only use separate appdomains when needed. The side effect of
this grouping is that all plugins in the same appdomain will get unloaded at
the same time. You could put each plugin into a separate appdomain but this
creates its own set of problems - each plugin is now remoted to all other
objects in other appdomains. When using separate appdomains you will need to
deal with issues related to assembly probing and versioning, resolving
references to other assemblies, ensuring that versioning differences in
common/shared assemblies are dealt with, etc.
If you are still in the design phase then you could add
serialize/deserialize methods to the plugin API to aid in preserving the
state. However, this assumes that a plugin is not in the middle of an
operation that cannot be interrupted, or is resumable. For a complex system
I would imagine you will need to deal with all the intricacies this
synchronization involves - querying each to determine if it is in a state
suitable to be unloaded, requesting it get to that state if it is not ready
to be shutdown, etc.
I don't know how many resources each appdomain consumes - I don't think it
would be an issue unless you are dealing with large numbers of appdomains
(of course, this begs the question of how many constitutes a "large"
system).
I think it's easier to manage the issues with a single appdomain, but this
also means that you must unload all the plugins to unload any of them.
"stu_pb" <st****@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
I am designing a plugin system for a window application using .NET(C#
specifically). One of the requirements of the plugin system is to be able
to
dynamically load/unload plugins.
My initial thought was to use System.Reflection.Assembly.Load to load the
plugins dynamically. This worked great, but I was left with no way to
dynamically unload the plugin.
So now I come to creating a new AppDomain for the plugins to reside in,
since the AppDomain can be unloaded. The problem I see with this is that
when I dynamically unload one plugin, the rest will have to be reloaded
and
any data will be lost. Is that true? I could notify the plugin when it
is
going to be unloaded and it could persist itself, or I could persist each
plugin automatically I suppose.
So I thought I could have an AppDomain for each plugin. Is this feasible?
Would this take up too many resources? Also in this case I would have to
have one instance of the assembly loader for each plugin since the
assembly
should be loaded from inside the current application domain.
I guess I am just looking for some opinions as to which approach is the
best, easiest or hopefully both!
Thanks for your help!