• 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 SpreadsheetControl 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.
IFormatDetectorService Allows detecting the format of a document contained in a stream.
ICustomCalculationService Allows managing the process of worksheet calculations.
IDefinedNameValidator A validator used to check whether a new version of the conflict defined name is valid and unique before pasting it into the destination document.
ICustomAssemblyLoadingNotificationService Enables determining whether a custom assembly containing the Entity Framework data model is allowed to load during mail merge.
IObjectDataSourceValidationService Allows custom validation of the ObjectDataSource data sources before using them in the document.
See Also