Skip to main content
A newer version of this page is available. .

Services

  • 2 minutes to read

A service is a class with a known interface, addressable by its type. A service can be obtained from a service provider, instantiated and stored within a service container. The SpreadsheetControl implements the base interfaces contained within the System.ComponentModel namespace of .NET - the IServiceProvider and IServiceContainer. You can obtain a service for the SpreadsheetControl by using the SpreadsheetControl.GetService<T> method.

When you get a service via the GetService method, you actually use the specified interface to obtain a pointer to an object that implements the methods of this interface. You can save this pointer (and the object it references), and delete the service implementation from the Spreadsheet using the SpreadsheetControl.RemoveService method. When it is done, the corresponding GetService method will return null.

At that time, you can install your own service using the SpreadsheetControl.AddService method. Subsequent calls to GetService will return the pointer to an object representing your service. So, the calls to service methods are simply redirected from the default implementation to a custom one. It is done silently and transparently for the caller.

This mechanism enables you to modify the default behavior of an application that uses these services at any time, without re-designing it.

Instead of the utilizing the GetService -> RemoveService -> AddService method sequence, you can use the generic SpreadsheetControl.ReplaceService<T> method.

SpreadsheetControl implements the following services.

Service Description
ISpreadsheetCommandFactoryService A service which is used to create Spreadsheet commands.
IMessageBoxService A service that enables you to display a custom message box when a runtime error occurs.
See Also