Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Do not export IServiceProvider #137

@AArnott

Description

@AArnott

VS extensions should not export System.IServiceProvider (without an explicit, non-default contract name). This is because this is a globally shared type name and if two folks exported it, it would cause everyone who imports it to fail since they expect only one export but got more than one. Generally speaking, you should only export your own types, or BCL types with an explicit contract name that has your namespace in it.

For example, this is wrong:

[Export(typeof(IServiceProvider))]

But this is OK:

[Export("Github.ExtensionForVS.IServiceProvider", typeof(IServiceProvider))]

This is where GitHub's extension violates this rule.

Now in this particular case, if the IServiceProvider that you actually want is the VS global service provider, you don't need to export anything, but simply import SVsServiceProvider (which derives from IServiceProvider):

[Import]
SVsServiceProvider GlobalServiceProvider { get; set; }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions