在我App.xaml.cs我有如何初始化MEF ServiceLocator.Current?
private void InitializeContainer()
{
var catalogs = new AggregateCatalog();
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
catalogs.Catalogs.Add(catalog);
// Also adding Interactions project
catalog = new AssemblyCatalog(typeof(InteractionsService).Assembly);
catalogs.Catalogs.Add(catalog);
// initialize the main application composition host (container)
CompositionHost.Initialize(catalogs);
}
但是,当我试图让对象初始化下来,像这样的一行:
this.InteractionsService = ServiceLocator.Current.GetInstance<IInteractionsService>();
我得到不同的是我的ServiceLocator.Current为空。
如何让它工作?
似乎没有这样的工作。 ComposeParts在Silverlight中不可用 – katit 2012-01-10 17:40:04
@katit在SL中有'Compose'?如果可能有帮助,我会用这种方法修改答案。 – 2012-01-10 21:44:21