2

I've an already existing project in C#. Now I should implement a plugin system. For this plugin system I've to implement a programming api/sdk. I dont want, that plugins have access to the assemblies that are used by my existing programm. This is the reason why I'll write a programming api that limit/specifcy the access to my programm. But how I could do this? Have I just create a new assemblies which references my assemblies from my existing project and expose specific functions with additional help of a facade pattern? Have someone another idea how I could solve this problem?

Marcel Hoffmann
  • 279
  • 3
  • 6
  • If you create a new assembly which references your assembly and uses functions from it, what would prevent a plugin author from referencing your assembly directly and using functions from it? – Rotem Oct 14 '15 at 09:53
  • This is the question. How can I prevent this? How can I expose only specific programm fetures? – Marcel Hoffmann Oct 14 '15 at 09:55
  • 1
    related: http://stackoverflow.com/questions/1520113/restrict-plug-in-assembly-code-access – Rotem Oct 14 '15 at 09:56
  • _Why_ do you not want the plugins to be able to access your asssemblies? – Thorbjørn Ravn Andersen Oct 14 '15 at 12:26
  • Perhaps you can use internal vs. public methods, [security contexts][https://msdn.microsoft.com/en-us/library/system.security.securitycontext%28v=vs.110%29.aspx], and things like [trusted and partially trusted assemblies][http://stackoverflow.com/q/376049/814206]. Not sure whether this direction will work or how it all would fit together, but it might be useful for you to look into. – Kasper van den Berg Oct 14 '15 at 19:49

1 Answers1

0

Do the plugins have to be dynamically loaded .NET assemblies? If you want to isolate the plugins from accessing your assemblies you might want to consider other plugin architectures:

  1. The plugins can be separate process and use interprocess communication to interact with the main application. That way the plugins will only have access to the API you choose to expose.

    C# has various was to do IPC - https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574%28v=vs.85%29.aspx - and there is also WCF which doesn't seem to be menitioned in that article - https://msdn.microsoft.com/en-us/library/ms735119.aspx

  2. You can embed a scripting language inside your main application, and the plugins will be written in that language. One of the most common scripting language used for this purpose is Lua, and the top google result for hosting it in .NET applications is NLua. You'll need to Sandbox the scripts to prevent them from accessing your assemblies. The interaction between the plugins and the main application is done by passing objects to the scripts.

Idan Arye
  • 12,032
  • 31
  • 40