-
Notifications
You must be signed in to change notification settings - Fork 1k
The Service Model
MonoDevelop 8.1 introduces a new model for implementing and consuming services. In previous versions MonoDevelop had a mix of approaches for implementing services. Some were implemented as instance classes, some as static classes, and there was no standard way of initializing them.
The new service model has three main goals:
- Homogenize how services are implemented, instantiated, initialized and accessed.
- Support asynchronous and on-demand initialization of services, to reduce and parallelize the of work that needs to be done at IDE startup.
- Improve support for unit testing by allowing discrete service initialization and using mock test services.
The model is very simple:
- The new ServiceProvider class provides methods for registering and getting references to services.
- Services implement the interface
IService, either directly or through the abstract classService. The interface defines the async methodTask Initialize(ServiceProvider)which is invoked the first time a service is requested.
In this new model all services are instances (no more static classes, with the exception of some special cases), and it is possible to get any service using the main service provider available in Runtime.ServiceProvider. The Runtime class also provides some shortcut methods for getting services. For example:
var fontService = await Runtime.GetService<FontService> ();
...
The ´GetService()` method can be used to get a service. Services are created on demand, so if the service has not been requested before, it will be created and initialized at this time.
Getting a service is an asynchronous operation (since it may involve initialization). This may not always be convenient, since services also need to be used from methods that are not asynchronous. To make use of services easier MonoDevelop.Ide defines the class IdeServices, which has references to all services that are initialized at startup. Referencing services from IdeServices is safe once the Ide is initialized. In some scenarios (such as in unit tests or when implementing a command line command), IdeServices still can be used, but will only have references to those services that have been initialized.
Bulding and Running
Writing Add-ins
MonoDevelop API
MonoDevelop Design and Architecure
- The Project Model
- Error and Exception Handling
- The Command System
- The Service Model
- The Document/View Model
MonoDevelop Coding Guides