using System.Collections.Generic;
public interface IPlugin {
public class ExamplePlugin: IPlugin {
public void Execute() { }
public class ExamplePluginTwo: IPlugin {
public void Execute() { }
public class PluginManager {
private Dictionary<string, IPlugin> _pluginDictionary = new Dictionary<string, IPlugin>();
public void Register(string pluginKey, IPlugin plugin) {
if (this._pluginDictionary.ContainsKey(pluginKey)) {
throw new Exception($"Plugin key: {pluginKey} already has a registered plugin.");
this._pluginDictionary.Add(pluginKey, plugin);
public void Execute(string pluginKey) {
if(!this._pluginDictionary.ContainsKey(pluginKey)) {
throw new Exception($"Unable to execute. Plugin key: {pluginKey} is not registered.");
this._pluginDictionary[pluginKey].Execute();
public class ExampleService {
private PluginManager _pluginManager = new PluginManager();
public ExampleService() {
this._pluginManager.Register("ExamplePlugin", new ExamplePlugin());
this._pluginManager.Register("ExampPluginTwo", new ExamplePluginTwo());
public void GetSomething(string pluginName) {
this._pluginManager.Execute(pluginName);
public static void Main()
ExampleService exampleService = new ExampleService();