Commands and Operations
When writing custom components you may want to take advantage of Geocortex Mobile's large built-in suite of command and operations or your own custom commands and operations.
Running Commands and Operations
Services and components can run commands and operations through dependency injection.
Implementing Commands and Operations
Services and components can also register an implementation for any command or operation. Commands and operations can either be registered and implemented directly in a service or component, or registered in a class that extends OperationsBase
for ease of use by other components and services.
note
Multiple implementations can be registered for a Command or Operation.
Direct Registration and Implementation
Commands and operations can be directly registered and implemented in a service or component through the IOperationRegistry
.
This pattern can be useful for registering dynamically generated commands or implementations.
important
It is vital that subscription handles are cleaned up when the object is cleaned up, otherwise dangling references can occur. This can be done by implementing the IDisposable
and IDisposableTracker
interface, and then providing this
as the second argument to a call to subscribe. ServiceBase
and ComponentBase
already implement these interfaces so you don't have to.
OperationsBase
Registration with Commands and operations can also be defined in an OperationsBase
class, which can then be injected into any service or component that wants to register an implementation.
- An
IVoidOperation
produces no output, and optionally takes an input.
- An
IOperation
produces an output, and optionally takes an input.
note
Operation names in Geocortex Mobile generally take the format <category>.<name>
, with multiple words kebab-cased
.
These types can be used to define a set of operations in an OperationsBase
class that is registered with Autofac. Implementations for the operations can then be registered in a service or component.
- OperationsBase
- Custom Component
Running Custom Commands
You can run the custom commands or operations you define by either injecting the appropriate OperationsBase
class or using the IOperationRegistry
to run the command or operation by name.
Relevant SDK Sample
The Geocortex Mobile SDK Samples project has a sample of implementing a command with a custom service.