Example #1
0
        /// <summary> 通过一个应用程序集创建一个MefEntityProvider </summary>
        public static MefEntityProvider <T> CreateInstance(Assembly ass)
        {
            MefEntityProvider <T> provider = new MefEntityProvider <T>();

            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(ass));

            var _container = new CompositionContainer(catalog);

            _container.ComposeParts(provider);

            return(provider);
        }
Example #2
0
        /// <summary> 通过一组应用程序集创建一个MefEntityProvider </summary>
        public static MefEntityProvider <T> CreateInstance(List <Assembly> asses)
        {
            //  ③ 必须拥有Export特性  [Export(typeof(IMefDemoBase))]
            MefEntityProvider <T> provider = new MefEntityProvider <T>();

            var catalog = new AggregateCatalog();

            asses.ForEach(l => catalog.Catalogs.Add(new AssemblyCatalog(l)));

            var _container = new CompositionContainer(catalog);

            _container.ComposeParts(provider);

            return(provider);
        }
Example #3
0
        static void Main(string[] args)
        {
            List <Assembly> ass = new List <Assembly>();

            ass.Add(Assembly.GetEntryAssembly());

            MefEntityProvider <IMefDemoBase> provider = MefEntityProvider <IMefDemoBase> .CreateInstance(ass);

            provider.DoList.ForEach(l => Console.WriteLine(l.ToString()));

            Console.Read();

            MefEntityProvider <IDisposable> provider1 = MefEntityProvider <IDisposable> .CreateInstance(ass);

            provider1.DoList.ForEach(l => Console.WriteLine(l.ToString()));

            Console.Read();
        }