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"));
            }
        }
    }

  • 相关阅读:
    (转)$.extend()方法和(function($){...})(jQuery)详解
    (转)JSONObject与JSONArray的使用
    (转)java中对集合对象list的几种循环访问总结
    ibatis 参数和结果的映射处理
    Could not calculate build plan
    maven项目工程报错:cannot be resolved to a type
    CronTrigger中cron表达式使用
    ex:0602-169 遇到不完整或无效的多字节字符,转换失败
    UseParNewGC和UseParallelGC的区别
    java gc日志详解
  • 原文地址:https://www.cnblogs.com/greefsong/p/3137766.html
Copyright © 2011-2022 走看看