Click here to Skip to main content
11,437,397 members (41,521 online)
Click here to Skip to main content
Add your own
alternative version

A Flexible Plugin System

, 3 Sep 2008 LGPL3
A generic plugin system used to load and manage plugins
fadd-15373.zip
trunk
dlls
xunit.dll
Examples
Plugins
ExampleApplication.Shared
Properties
ExampleApplication
Properties
ExamplePlugin.Shared
Properties
ExamplePlugin
Properties
Fadd.Globalization.Yaml
fadd.snk
Properties
Tests
fadd
Commands
Net
Tests
fadd.snk
Globalization
Tests
Logging
Plugins
Properties
Tests
Validation
using System;
using System.Collections.Generic;
using ExampleApplication.Shared;
using ExamplePlugin.Shared;
using Fadd.Plugins;

namespace ExamplePlugin
{
    public class MyPlugin : IMyPlugin
    {
        private const string _pluginName = "MyPlugin";
        private readonly IPluginInfo _pluginInfo = new MyPluginInfo();
        private readonly IEnumerable<string> _dependencies = new List<string>();

        /// <summary>
        /// This name is used to determine dependencies, should always be in english. 
        /// Should not be confused with the human friendly name in <see cref="IPlugin.PluginInfo"/>.
        /// </summary>
        public string PluginName
        {
            get { return _pluginName; }
        }

        /// <summary>
        /// Information about the plugin.
        /// </summary>
        public IPluginInfo PluginInfo
        {
            get { return _pluginInfo; }
        }

        /// <summary>
        /// Other plugins that this one depends on. The list should contain <see cref="PluginName"/>s.
        /// </summary>
        /// <value>Is never null</value>
        public IEnumerable<string> Dependencies
        {
            get { return _dependencies; }
        }

        /// <summary>
        /// Start the plugin
        /// </summary>
        /// <param name="application">Application interface exposed towards the plugins.</param>
        public void Start(IApplication application)
        {
            IMyApplication myApplication = (IMyApplication) application;
            myApplication.RegisterComponent<IWorldPeace>(new WorldPeaceThroughLove());
            myApplication.AddMenuItem("Click me", OnClick);
        }

        /// <summary>
        /// Invoked when the user clicks on our menu item
        /// </summary>
        /// <param name="name"></param>
        private void OnClick(string name)
        {
            Console.WriteLine("Omg! You clicked me!");
        }

        /// <summary>
        /// Function that must be implemented
        /// </summary>
        /// <param name="name"></param>
        public void SayHelloTo(string name)
        {
            Console.WriteLine("Hello " + name);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

Share

About the Author

jgauffin
Founder Gauffin Interactive AB
Sweden Sweden
Founder of OneTrueError, a .NET service which captures, analyzes and provide possible solutions for exceptions.

blog | twitter
Follow on   Twitter   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150428.2 | Last Updated 3 Sep 2008
Article Copyright 2008 by jgauffin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid