MEF太难了,根本搞不懂。解决方案
MEF太难了,根本搞不懂。
下载了一个入门代码,里面有几个东西,在MSDN上面都查不到的,比如AttributedAssemblyPartCatalog
在主函数Run里面的。
根本没有这个东西啊,调试不出来。。。
哪儿错了?
------解决方案--------------------
MEF 接口就那么几个,应该不难学。要看源码直接从 codeplex 上下好了。
下载了一个入门代码,里面有几个东西,在MSDN上面都查不到的,比如AttributedAssemblyPartCatalog
在主函数Run里面的。
根本没有这个东西啊,调试不出来。。。
哪儿错了?
- C# code
using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; using System.Reflection; namespace HelloWorld { class Program { [Import] public string Message { get; set; } public class SimpleHello { [Export] public string Message { get { return "Hello World!"; } } } public void Run() { var catalog=new AttributedAssemblyPartCatalog(Assembly.GetExecutingAssembly()); var container=new CompositionContainer(catalog.CreateResolver()); container.AddPart(this); container.Compose(); Console.WriteLine(Message); Console.ReadKey(); } static void Main(string[] args) { Program pg = new Program(); pg.Run(); } } }
------解决方案--------------------
MEF 接口就那么几个,应该不难学。要看源码直接从 codeplex 上下好了。