Skip to content

Why does ServiceProvider.GlobalProvider.GetService always return null in my command handler? #489

Answered by reduckted
aglasencnik asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, it's a MEF export. 🤦‍♂️ Sorry, I got myself confused between the ICommandHandler and the command interceptors in the toolkit.

Since it's a MEF export, you won't be able to pass the package to the constructor like I suggested, however you should be able to register the package as a service. Doing that will mean you can retrieve it using GetService.

On your package, add this attribute:

[ProvideService(typeof(GraphvizVSPackage), IsAsyncQueryable = true)]
public class GraphvizVSPackage : ToolkitPackage

And then in the InitializeAsync method, add the service:

protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
    Ad…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@aglasencnik
Comment options

@aglasencnik
Comment options

@reduckted
Comment options

Answer selected by aglasencnik
@aglasencnik
Comment options

@aglasencnik
Comment options

@aglasencnik
Comment options

@aglasencnik
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants