Share via


Obtaining and Using Host Services

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The Recipe Framework follows the design of the .NET service component model. The Recipe Framework itself is a set of components sited inside a Visual Studio Integration Package. The Integration Package acts as a container and allows the components to access services from Visual Studio.

Actions are at the bottom of the component hierarchy so they can request services of all components above them, including Visual Studio itself.

The following services can be useful while writing actions, value providers, converters, and editors:

  • DTE. This is the root of the object hierarchy of Visual Studio. It provides access to all the functionality exposed by Visual Studio to manage solutions, projects, and the build process. You can manipulate this service to perform any action an add-in can do.
  • IAssetReferenceService. This service allows a component to add references to recipes and templates for later execution by the user. It is also possible to add references with initial state, iterate over them, or even remove them. This service is typically used in a binding recipe action.
  • ITypeResolutionService. This service is used to retrieve types that must be resolved relative to the Guidance Package installation folder.
  • IDictionaryService. This service allows inspection of all argument values in the currently executing recipe. The service is useful to value providers, converters, and value editors. For actions, you should use the Input and Output properties to access values.
  • IConfigurationService. This service allows inspection of the configuration information of the executing recipe.
  • IExecutionService. This service allows execution of a recipe. It is useful if you are developing custom recipe references and want to perform pre-processing or post-processing when a recipe is executed. These references, using their Execute methods, can delegate the call to this service, or even do something else altogether, and not execute a recipe at all.
  • IOutputWindowService. This service is used to directly write messages to the output window. However, the recommended way to log messages is to use the System.Diagnostics.Trace class, which also logs to the output window corresponding to the Guidance Package that owns the component.

The following code example shows how an action can request an instance of a service.

IAssetReferenceService references=(IAssetReferenceService)GetService(typeof(IAssetReferenceService));

For components inheriting from SitedComponent, such as an Action-derived class, you can also use the generics version:

IAssetReferenceService references = GetService<IAssetReferenceService>(true);

The Boolean passed to the method makes sure that the call to GetService returns a non-null instance of the service.

See also

Developing Actions | Writing Action Classes | Raising Exceptions