Wolfringo Wolfringo
Wolfringo Wolfringo
Wolfringo (c) 2020 TehGM
DocFX, DiscordFX theme.
Search Results for

    Class CommandsService

    A service that deals with commands loading, initialization and execution.

    Inheritance
    System.Object
    CommandsService
    Implements
    ICommandsService
    System.IDisposable
    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 System.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 Source

    CommandsService(IServiceProvider, CommandsOptions)

    Initializes a command service.

    Declaration
    public CommandsService(IServiceProvider services, CommandsOptions options)
    Parameters
    Type Name Description
    System.IServiceProvider services

    Service provider to resolve dependencies from

    CommandsOptions options

    Commands options to use for all commands.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    Microsoft.Extensions.Logging.ILogger log

    Logger to log messages and errors to. If null, all logging will be disabled.

    Properties

    | Improve this Doc View Source

    Commands

    Descriptors of all commands loaded to this commands service.

    Declaration
    public IEnumerable<ICommandInstanceDescriptor> Commands { get; }
    Property Value
    Type Description
    System.Collections.Generic.IEnumerable<ICommandInstanceDescriptor>

    Methods

    | Improve this Doc View Source

    BuildDefaultServiceProvider(IWolfClient, CommandsOptions, ILogger)

    Builds default service provider. Used to temporarily support obsolete non-builder constructors.

    Declaration
    [Obsolete]
    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.

    Microsoft.Extensions.Logging.ILogger log

    A logger to add to the services. If null, logging will be disabled.

    Returns
    Type Description
    System.IServiceProvider

    A System.IServiceProvider with default services added.

    | Improve this Doc View Source

    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 System.IDisposable.

    | Improve this Doc View Source

    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.

    System.Threading.CancellationToken cancellationToken

    Cancellation token to cancel execution with.

    Returns
    Type Description
    System.Threading.Tasks.Task<ICommandResult>

    Result of the execution.

    | Improve this Doc View Source

    StartAsync(CancellationToken)

    Starts the Command Service.

    Declaration
    public async Task StartAsync(CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    System.Threading.CancellationToken cancellationToken

    Cancellation token to cancel loading with.

    Returns
    Type Description
    System.Threading.Tasks.Task
    Remarks

    Once already started, calling this method again will cause commands to be re-loaded.

    Implements

    ICommandsService
    System.IDisposable