如何确保我的服务在AsyncPackage
我的 Visual Studio 扩展中注册?我一直在关注VSSDK-Extensibility-Samples 的示例。我还研究了其他扩展是如何做到的。我尝试做同样的事情,但我无法从全球服务提供商那里获得我的服务。
我做的步骤:
[Shell.ProvideService(typeof(SMyService), IsAsyncQueryable = true)]
对于我的异步包类[Guid(...)] interface SMyService { }
在新文件中定义接口public class MyService { }
作为服务实现。它是由CreateServiceAsync
方法创建的var container = (Shell.IAsyncServiceContainer)this; container.AddService(typeof(SMyService), CreateServiceAsync);
AsyncPackage.InitializeAsync
调用前 的方法内部base.InitializeAsync
我是否缺少使我的服务可以从其他 VS 扩展服务访问的东西?当我AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SMyService))
在说 MEF 组件方法中执行时,我得到一个空值。我需要在其他任何地方注册服务吗?