在 VSTO 项目中使用 MEF 并定义容器如下
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(this.GetType().Assembly));
catalog.Catalogs.Add(...);
container = new CompositionContainer(catalog);
container.SatisfyImportsOnce(this);
除了代码使用的地方,使用各种库都运行良好
ServiceLocator.Current.GetInstance<MyInterface>()
这当然会引发 NullReferenceException
考虑到 ServiceLocator 在它自己的 dll 中,想知道如何连接它,或者它甚至可能吗?