How to use Plugin Architecture in ASP.NET?

后端 未结 2 1027
暗喜
暗喜 2021-02-04 21:37

I really like the plugin architecture of WinForms and I want to use a plugin architecture in Asp.net.

I\'ve searched for plugins architecture in asp.net and I\'ve found

相关标签:
2条回答
  • 2021-02-04 21:46

    You can roll your own.

    A plugin architecture needs a few not-so-complex parts:

    • A way to identify where the plugin dll is located
    • An interface or base class definition that all plugins must adhere to. This is the most important one. It decides what functionality your plugin can expose and how deeply it can integrate with your app
    • A place (in time) when your plugin gets loaded and executed. (ie, does the plugin execute for each web page request? Or for requests matching a certain name? Or does the page manually invoke plugins?)

    Once you have this figured out, instantiating an instance of a plugin is simple. It works the same regardless of whether you're running in a web app or on the client:

    System.Reflection.Assembly a = System.Reflection.Assembly.LoadFrom(plugin_path);
    t = a.GetType("IPlugin");
    IPlugin plugin = (IPlugin)Activator.CreateInstance(t);
    

    then, you can use plugin.DoSomething() to actually invoke functionality from the plugin. (Whether it is to render part of the html or save to a DB or whatever)

    0 讨论(0)
  • 2021-02-04 22:11

    Look at Managed Extensibility Framework

    0 讨论(0)
提交回复
热议问题