zoukankan      html  css  js  c++  java
  • MEF插件开发案例

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel.Composition;

    namespace WebApplication3
    {
       
       public interface ICalculator
        {
            String Calculate(String input);
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ComponentModel.Composition;

    namespace WebApplication3
    {
        [Export(typeof(ICalculator))]
        public class MySimpleCalculator : ICalculator
        {
            public string Calculate(string input)
            {
                return "MySimpleCalculator 处理了" + input;

            }

        }


    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ComponentModel.Composition.Hosting;
    using System.ComponentModel.Composition;
    using System.Reflection;

    namespace WebApplication3
    {
        public class ComposCLass
        {
            private CompositionContainer _container;
            [Import]
            public ICalculator calculator1{set;get;}
            public ComposCLass()
            {
                Compose();
            }

            public void Compose()
            {
                var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

                _container = new CompositionContainer(catalog);
                try
                {
                    this._container.ComposeParts(this);
                }
                catch (CompositionException compositionException)
                {
                }
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel.Composition;
    using System.ComponentModel.Composition.Hosting;
    namespace WebApplication3
    {
     


        public partial class WebForm2 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                ComposCLass classp = new ComposCLass();
                //classp.Compose();
                Response.Write(classp.calculator1.Calculate("asldhcgashdcbgalshdcblasdhc"));
            }
        }
    }

  • 相关阅读:
    企业移动化?AppCan教你正确的打开方式
    企业该如何挑选移动平台?
    除了移动开发,一个好平台还需要具备什么功能?
    canvas绘制工作流之绘制节点
    canvas与工作流的不解之缘
    一个工作流引擎诞生前的准备工作
    欢迎大家Follow me!微软MVP罗勇(Dynamics CRM方向2015-2018年)欢迎您!
    Dynamics 365定制:在实体的列表界面添加按钮
    Dynamics 365 Customer Engagement中自定义工作流活动的调试
    Dynamics CRM 2015/2016新特性之二十七:使用Web API查询元数据
  • 原文地址:https://www.cnblogs.com/greefsong/p/3137766.html
Copyright © 2011-2022 走看看