Plugins in .NET
Using the newest version of .NET, how well can a plugin system be implemented where plugins
a) are loaded at runtime
b) are unloaded at runtime
c) can depend on each other
d) can optionally depend on each other
a, b and c can be achieved with
AssemblyLoadContext, can d?13 Replies
Yes
You still have to use reflection though from what I know of
For d?
Or for all of the above?
a-c, not sure about d
Although reflection can probably solve #d as well
I suppose reflection cannot be reasonably avoided for the plugin scenario.
Right
Is there other pattern for optional dependency, other than using instances from the other assembly in a
try-catch? I expect negative, but I wanted to check.I would recommend to make some kind of "SDK" for the plugins to use.
that carries metadata, etc.
That's interesting, thank you
Except b, I think MEF covers the rest already, https://www.nuget.org/packages/system.composition
MEF was mainly designed for VS I think, and VS today still supports it https://microsoft.github.io/vs-mef/docs/why.html MSDI is a more generic underlying infrastructure IMHO.
Doesn't this unload it? https://learn.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext.unload?view=net-9.0
AssemblyLoadContext.Unload Method (System.Runtime.Loader)
Initiates an unload of this AssemblyLoadContext.
that does basically nothing
(the only thing it does it make ALC.Load throw iirc)
Interesting.
It seems like samples has a demo on proper unloading https://github.com/dotnet/samples/tree/main/core%2Ftutorials%2FUnloading
Unknown User•4d ago
Message Not Public
Sign In & Join Server To View