如何创建可插拔ASP.Net网站? [英] how to create pluggable ASP.Net website?

查看:237
本文介绍了如何创建可插拔ASP.Net网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是创建一个网站,提供了开发插件它能力的最佳做法是什么?

What are the best practices to create a site, with ability to develop plugins for it?

像你想创建一个博客模块,并且希望用户或合作开发者添加插件来扩展此模块功能。

Like you want to create a blog module, and you want users or co-developers to add plugins to extend this module functionality.

更新:
感谢您的超高速答案,但我认为这是超必杀我。是不是有一个简单的解决方案,就像我看到blogengine插件创建系统,你只需要装饰类的插件使用[扩展]。

Update: Thanks for the ultra speed answers, but I think this is over kill for me. Isn't there a simpler solution, like I have seen blogengine plugin creation system is you just have to decorate the class plugin with [Extension].

我有点中期核心开发人员,所以我想的基类,继承,接口,你有什么感想?

I am kind of mid core developer, so I was thinking of base class, inheritance, interfaces, what do you think ?

推荐答案

修改

我完全基于你的问题编辑改写了我的答案。

I completely rewrote my answer based on your question edit.

让我告诉你这是多么容易实现的插件架构只用最少的步骤。

Let me show you just how easy it is to implement a plugin architecture with just the minimal steps.

第1步:定义你的插件都将实现一个接口

namespace PluginInterface
{
    public interface IPlugin
    {
        string Name { get; }
        string Run(string input);
    }
}

第2步:创建一个实现IPlugin一个插件

namespace PluginX
{
    using PluginInterface;

    public class Plugin : IPlugin
    {
        public string Name
        {
            get { return "Plugin X"; }
        }

        public string Run(string input)
        {
            return input;
        }
    }
}

第三步:运行插件

namespace PluginTest
{
    using System;
    using System.IO;
    using System.Runtime.Remoting;
    using PluginInterface;

    class Program
    {
        static void Main( string[] args )
        {
            string pluginFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PluginX.dll");
            ObjectHandle handle = Activator.CreateInstanceFrom(pluginFile, "PluginX.Plugin");

            IPlugin plugin = handle.Unwrap() as IPlugin;

            string pluginName = plugin.Name;
            string pluginResult = plugin.Run("test string");          

        }
    }
}

请记住,这仅仅是一个插件architechure的基础上,最简单的例子。你也可以做的事情,如

Keep in mind, this is just the basic, most straightforward example of a plugin architechure. You can also do things such as


  • 创建一个插件主机运行的内你的插件它自己的的AppDomain

  • 选择任一接口,抽象类,或属性与装饰你的插件

  • 使用反射,接口,IL-发出的thunk或委托来完成后期装订作业

如果你的设计使然。

这篇关于如何创建可插拔ASP.Net网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆