Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] .NET plugin framework - executing host's methods from a plugin?

Started by mijapkos Jun 28, 2007 at 5:58 AM 0 replies 800+ views
Original Post
mijapkos
mijapkos
I'm trying to write a plugin framework which uses appdomains to run the plugins. Everything is going nicely but there's one problem: I would like to have a "library" in my host application with methods like "WriteToScreen(text)", "ClearScreen()" etc. and I would like to use my plugins to access these functions. So for example one of my plugins would contain stuff like: host.ClearScreen(); host.RemoveWindowSize(640,480); host.WriteToScreen("This is my plugin writing"); I haven't found any tutorials about this and I just can't get my head around the problem. With the host and the plugins in the same appdomain this should be easier but I want to be able to update the plugins without closing my host-application, so I have to use secondary appdomain for running the plugin. So my question, finally, is that has anyone solved this problem before and if yes, how? Or does someone know any tutorials about the subject? Thanks for answers in advance. [Edited by - mijapkos on June 28, 2007 6:36:49 AM]
benryves
benryves
I'd pass an instance of the host (or maybe a special 'host controller' that contains limited functionality?) to the constructor of the plugin.

public class Plugin {    public readonly HostController Controller;    public Plugin(HostController controller) {        this.Controller = controller;    }}


...and in the plugin itself:
public class CustomPlugin : Plugin {    public CustomPlugin(HostController controller)        : base(controller) {        }    public void SomeMethod() {        this.Controller.ClearScreen();    }}


Alternatively, you could move the methods you wish to expose into the Plugin class itself.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.