Visual Studio Extension - Registering a new service

349 Views Asked by At

How do I make sure my service gets registered in the AsyncPackage of my Visual Studio extension? I have been following a sample from VSSDK-Extensibility-Samples. I have also taken a look at how other extensions do it. I tried to do the same yet I cannot obtain my service from global service provider.

Steps I did:

  • [Shell.ProvideService(typeof(SMyService), IsAsyncQueryable = true)] for my async package class
  • [Guid(...)] interface SMyService { } defined interface in a new file
  • public class MyService { } as service implementation. It is created by CreateServiceAsync method
  • var container = (Shell.IAsyncServiceContainer)this; container.AddService(typeof(SMyService), CreateServiceAsync); inside of AsyncPackage.InitializeAsync method before calling base.InitializeAsync

Is there something I am missing to make my service accessible from other VS Extextension services? When I Do AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SMyService)) inside of say MEF component method I get a null. Do I need to register the service anywhere else?

0

There are 0 best solutions below