Hi guys,

I've got an idea but I'm struggling to understand perhaps how one would go about implementing a solution.

Basucally I've got a .NET or more so C# UI that loads plugins using reflection. this all works fine but now I'm wondering if its possible to load the C# project and have UI's that are also plugins. This way I can lanuched either a windows UI or a ASP page depending which DLL is loaded.

Is this possoble?

J.

Dani AI

Generated

Short answer: yes — but treat UI and persistent logic as separate plugin concerns. Loadable DLLs can provide either a desktop view or a web view, but a single plugin should expose a small, stable contract (model + operations) and then provide host-specific adapters for WinForms or ASP.NET. Put those interfaces and lightweight DTOs in a tiny shared assembly so both the host and plugins compile against the same contract.

A minimal contract example:

[Serializable]
public class MyDocument
{
    public string Title { get; set; }
    public string Content { get; set; }
}

public interface IDataSaver
{
    bool Save(MyDocument doc);
}

public interface IWinFormsUiPlugin
{
    System.Windows.Forms.Control GetView(); // desktop host can embed this
}

public interface IWebUiPlugin
{
    string RenderHtml(MyDocument doc); // web host can call this during page rendering
}

public interface IPluginHost
{
    void Notify(string message);
}

Practical notes and two-way comms: don’t pass Form or control trees into savers — that becomes brittle (as warned) and loses event wiring. Instead pass serializable models (MyDocument) and use an IPluginHost callback for progress or prompts. If you load plugins into a separate AppDomain for isolation/unload, objects crossing boundaries must be serializable or derive from MarshalByRefObject; otherwise marshal data only. Also remember WinForms controls must be manipulated on the UI thread (call Invoke/BeginInvoke).

Tooling/deployment tips: keep the shared contract tiny and versioned, deploy plugin assemblies to per-plugin folders and load via reflection or a composition framework. Consider MEF for composition to reduce boilerplate. For AppDomain behavior and isolation guidance see the Microsoft docs for MEF and AppDomain:
Managed Extensibility Framework (MEF)
AppDomain class (cross-AppDomain considerations)

Tie the host to model-based plugins, provide UI adapters per host type, and use callbacks or events for two-way comms — that will keep the design flexible and maintainable.

Recommended Answers

All 3 Replies

Check out these links:



http://www.codeproject.com/KB/cs/pluginsincsharp.aspx

http://www.c-sharpcorner.com/uploadfile/rmcochran/plug_in_architecture09092007111353am/plug_in_architecture.aspx

Thanks for those Kimpl. Do you know how to obtain 2 way communication between the UI (main project) and the DLL project? Basically I want to save my object decalred in the UI to a file. However this "file saver" should be put into a DLL so that the user can use my UI to decide how to "save" the data, if this make sense?

Pass the form object to the DLL and have it walk the control structure saving all the control information. You'll have problems with events, though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.