Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Collapse]ASP.NET Controls and MVC Extensions
 [Expand]Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Collapse]ASP.NET WebForms Controls
  [Expand]Reporting
  [Expand]Chart Control
  [Expand]Grid View
  [Expand]Card View
  [Expand]Vertical Grid
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Image and Data Browsing
  [Expand]Docking and Popups
  [Expand]Site Navigation and Layout
  [Expand]File Management
  [Expand]Multi-Use Site Controls
  [Collapse]Scheduler
   [Expand]Product Information
    Getting Started
   [Expand]Fundamentals
   [Collapse]Concepts
    [Expand]Scheduler Elements
    [Expand]Appointments
    [Expand]Resources
    [Expand]Views
     Data Binding
    [Collapse]Services
      Introduction to Services
      DateTime Navigation Services
      Resource Navigation Services
      Selection Service
      Appointment Selection Service
      Formatting Services
     Templates
     Client-Side Functionality
     Callback Commands
    [Expand]Reporting
     Time Zones
     Keyboard Shortcuts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End-User Capabilities
   [Expand]Member Tables
  [Expand]HTML Editor
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gauges
  [Expand]Data Editors
  [Expand]Spell Checker
  [Expand]Query Builder
 [Expand]ASP.NET MVC Extensions
 [Expand]Localization
 [Expand]Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Introduction to Services

This document briefly introduces the concept of services applied to the ASPxScheduler component object model.

Functionality enhancements of ASPxScheduler 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? 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 core of ASPxScheduler and 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 by supplying the type of the service to the ASPxScheduler.GetService 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 the 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.

Previously, services could present challenges to a developer because of the service's obscure nature - you had to possess 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 ASPxScheduler.Services property to access ASPxScheduler services, so their methods become easily discoverable. Hence, instead of the code above you can write:

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

For deeper insight into service containers and related concepts, refer to the Lightweight Containers and Plugin Architectures: Dependency Injection and Dynamic Service Locators in .NET article by Daniel Cazzulino. He analyzes an article Inversion of Control Containers and the Dependency Injection pattern by Martin Fowler in light of .NET, and elaborates the idea.

How would you rate this topic?​​​​​​​