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
Buddy
Buddy5d ago
Yes You still have to use reflection though from what I know of
Sebastian Thomas
Sebastian ThomasOP5d ago
For d? Or for all of the above?
Buddy
Buddy5d ago
a-c, not sure about d Although reflection can probably solve #d as well
Sebastian Thomas
Sebastian ThomasOP5d ago
I suppose reflection cannot be reasonably avoided for the plugin scenario.
Buddy
Buddy5d ago
Right
Sebastian Thomas
Sebastian ThomasOP5d ago
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.
Buddy
Buddy5d ago
I would recommend to make some kind of "SDK" for the plugins to use. that carries metadata, etc.
Sebastian Thomas
Sebastian ThomasOP5d ago
That's interesting, thank you
Lex Li
Lex Li4d ago
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.
Petris
Petris4d ago
that does basically nothing (the only thing it does it make ALC.Load throw iirc)
Buddy
Buddy4d ago
Interesting. It seems like samples has a demo on proper unloading https://github.com/dotnet/samples/tree/main/core%2Ftutorials%2FUnloading
Unknown User
Unknown User4d ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?