Class CommandsService
A service that deals with commands loading, initialization and execution.
Namespace: TehGM.Wolfringo.Commands
Assembly: Wolfringo.Commands.dll
Syntax
public class CommandsService : ICommandsService, IDisposable
Remarks
This is a default service that runs the commands. It'll manage all other parts of Commands System.
This command service can be customized partially by injecting custom services into its constructor. If these services are set to default or skipped, default instances will be automatically created and used, similarly to WolfClient.
Constructor takes IServiceProvider as one of params. Services contained in that provider will be used by default. If service cannot be resolved, or the provider is null, a fallback provider will be used.
This hierarchy is used through entire command execution, so custom provider does not need to specify services required by Commands Service.
Fallback provider will create services only if they are not provided via custom provider.
Services injected via custom provider will NOT be disposed when Dispose() is invoked. Please dispose them manually.
Constructors
| Improve this Doc View SourceCommandsService(IServiceProvider, CommandsOptions)
Initializes a command service.
Declaration
public CommandsService(IServiceProvider services, CommandsOptions options)
Parameters
Type | Name | Description |
---|---|---|
IServiceProvider | services | Service provider to resolve dependencies from |
CommandsOptions | options | Commands options to use for all commands. |
CommandsService(IWolfClient, CommandsOptions)
Initializes a command service.
Declaration
[Obsolete("Use CommandsServiceBuilder instead")]
public CommandsService(IWolfClient client, CommandsOptions options)
Parameters
Type | Name | Description |
---|---|---|
IWolfClient | client | WOLF client. Required. |
CommandsOptions | options | Commands options that will be used as default when running a command. Required. |
CommandsService(IWolfClient, CommandsOptions, ILogger)
Initializes a command service.
Declaration
[Obsolete("Use CommandsServiceBuilder instead")]
public CommandsService(IWolfClient client, CommandsOptions options, ILogger log)
Parameters
Type | Name | Description |
---|---|---|
IWolfClient | client | WOLF client. Required. |
CommandsOptions | options | Commands options that will be used as default when running a command. Required. |
ILogger | log | Logger to log messages and errors to. If null, all logging will be disabled. |
Properties
| Improve this Doc View SourceCommands
Descriptors of all commands loaded to this commands service.
Declaration
public IEnumerable<ICommandInstanceDescriptor> Commands { get; }
Property Value
Type | Description |
---|---|
IEnumerable<ICommandInstanceDescriptor> |
Methods
| Improve this Doc View SourceBuildDefaultServiceProvider(IWolfClient, CommandsOptions, ILogger)
Builds default service provider. Used to temporarily support obsolete non-builder constructors.
Declaration
protected static IServiceProvider BuildDefaultServiceProvider(IWolfClient client, CommandsOptions options, ILogger log = null)
Parameters
Type | Name | Description |
---|---|---|
IWolfClient | client | Wolf Client to use with CommandsService. |
CommandsOptions | options | Options for commands service. |
ILogger | log | A logger to add to the services. If null, logging will be disabled. |
Returns
Type | Description |
---|---|
IServiceProvider | A IServiceProvider with default services added. |
Dispose()
Disposes the Command Service.
Declaration
public void Dispose()
Remarks
This method will dispose services created by default if they weren't provided via the constructor. If service was provided via constructor, it will NOT be disposed - please dispose it manually when convenient.
This method will also dispose all command instances and descriptors that happen to implement IDisposable.
ExecuteAsync(ICommandContext, CancellationToken)
Executes commands against a command context.
Declaration
public async Task<ICommandResult> ExecuteAsync(ICommandContext context, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
ICommandContext | context | Context to execute commands with. |
CancellationToken | cancellationToken | Cancellation token to cancel execution with. |
Returns
Type | Description |
---|---|
Task<ICommandResult> | Result of the execution. |
StartAsync(CancellationToken)
Starts the Command Service.
Declaration
public async Task StartAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Cancellation token to cancel loading with. |
Returns
Type | Description |
---|---|
Task |
Remarks
Once already started, calling this method again will cause commands to be re-loaded.