Partilhar via


IFeatureService Interface

Definition

Service that keeps track of IFeatureController's requests to disable a feature in given scope. When multiple IFeatureControllers disable a feature and one IFeatureController enables it back, it will not interfere with other disable requests, and feature will ultimately remain disabled.

While this service does have a thread affinity, its implementation does not guarantee thread safety. It is advised to change feature state from UI thread, otherwise simultaneous changes may result in race conditions.

public interface class IFeatureService
public interface IFeatureService
type IFeatureService = interface
Public Interface IFeatureService

Examples

In an exported MEF part:

[Import]
IFeatureServiceFactory FeatureServiceFactory;

IFeatureService globalService = FeatureServiceFactory.GlobalFeatureService;
IFeatureService localService = FeatureServiceFactory.GetOrCreate(scope); // scope is an IPropertyOwner

// Also have a reference to <xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Utilities.IFeatureController"></xref>:
IFeatureController MyFeatureController;
// Interact with the <xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Utilities.IFeatureService"></xref>:
globalService.Disable(PredefinedEditorFeatureNames.Popup, MyFeatureController);
localService.IsEnabled(PredefinedEditorFeatureNames.Completion); // returns false, because Popup is a base definition of Completion and because global scope is a superset of local scope.

Methods

Disable(String, IFeatureController)

Disables a feature.

GetCookie(String)

Creates a new IFeatureCookie that provides O(1) access to the feature's value, in this service's scope. The IFeatureCookie is updated when the feature or its base is updated in this scope or in the global scope.

IsEnabled(String)

Checks if feature is enabled. By default, every feature is enabled.

Events

StateUpdated

Provides a notification when this feature or its base feature was updated. We use FeatureUpdatedEventArgs and not FeatureChangedEventArgs because there are base features and disable requests from parent scopes that affect the factual state of given feature. We use this event to let the interested parties (IFeatureCookie) recalculate the actual state of the feature.

Applies to