[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Collapse]Scheduler
   [Expand]Product Information
    Getting Started
   [Expand]Scheduler Elements and Structure
   [Expand]Data Binding
   [Expand]Appointments
   [Expand]Views
   [Expand]Supported Formats
    Printing
   [Expand]Scheduler Reporting
   [Expand]Time Zones
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
   [Collapse]Services
     Introduction to Services in XtraScheduler
     Keyboard Services
     Mouse Services
     DateTime Navigation Services
     Resource Navigation Services
     Scheduler State Service
     Formatting Services
     Appointment Selection Service
     Selection Service
     Command Factory Service
   [Expand]Member Tables
   [Expand]Visual Elements
   [Expand]Examples
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Introduction to Services in XtraScheduler

This document briefly introduces the concept of services and containers applied to the XtraScheduler component object model.

Functionality enhancements of XtraScheduler may require intense code modifications, and result in properties and methods becoming obsolete. To minimize the chance of breaking changes in future versions, we decided to separate the actual implementation of a feature in code from the implementation of methods used to access this feature. We can manage this task via extensive use of interfaces. It was also necessary to find a way to break apart dependencies in the application, and achieve looser coupling between its parts. This approach usually results in greater extensibility.

To achieve this, we decided to follow a concept of services and service containers, implemented in .NET framework.

What is a service? 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 XtraScheduler incorporates classes and interfaces that inherit from base interfaces, contained within the System.ComponentModel namespace of .NET - first of all, System.IServiceProvider and System.ComponentModel.Design.IServiceContainer. Since the Scheduler implements the IServiceProvider interface, you can obtain a service using the SchedulerControl.GetService or the SchedulerControl.GetService<T> method, as illustrated below:

This code tries to get a reference to a service which is responsible for moving backwards and forwards to different points in time within the scheduler's coordinate system. An implicit cast is required because GetService method returns a System.Object.

Note

Note that the service availability is not guaranteed. Whenever you query a service type by calling the GetService method, you must always check if GetService returned a valid object. Or, you may use the generic SchedulerControl.GetService<T> method.

Previously services could present challenges to a developer because of the service's obscure nature - you had to possess a prior knowledge of the service type and its methods to use it, and there was no Intellisense to guide you. Nowadays you can use the dot(.) operator with the SchedulerControl.Services property to access XtraScheduler services, so their methods become easily discoverable.

You can add your own services to the service container via the SchedulerControl.AddService method, and use them throughout your application. Do not forget to remove them using a SchedulerControl.RemoveService method for the proper disposal of a container when it is no longer needed.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T224044.

Is this topic helpful?​​​​​​​