Class CommandsLoader
A service that loads Command instance descriptors from types and assemblies.
Implements
Namespace: TehGM.Wolfringo.Commands.Initialization
Assembly: Wolfringo.Commands.dll
Syntax
public class CommandsLoader : ICommandsLoader
Constructors
| Improve this Doc View SourceCommandsLoader(ICommandInitializerProvider, ILogger)
Creates a new loader instance.
Declaration
public CommandsLoader(ICommandInitializerProvider initializers, ILogger log = null)
Parameters
Type | Name | Description |
---|---|---|
ICommandInitializerProvider | initializers | Command initializers mapping. |
ILogger | log | Logger to log messages and errors to. If null, all logging will be disabled. |
CommandsLoader(ICommandInitializerProvider, ILogger<CommandsLoader>)
Creates a new loader instance.
Declaration
public CommandsLoader(ICommandInitializerProvider initializers, ILogger<CommandsLoader> log)
Parameters
Type | Name | Description |
---|---|---|
ICommandInitializerProvider | initializers | Command initializers mapping. |
ILogger<CommandsLoader> | log | Logger to log messages and errors to. If null, all logging will be disabled. |
Methods
| Improve this Doc View SourceLoadFromAssemblyAsync(Assembly, CancellationToken)
Loads all command instance descriptors from an assembly.
Declaration
public Task<IEnumerable<ICommandInstanceDescriptor>> LoadFromAssemblyAsync(Assembly assembly, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Assembly | assembly | Assembly to load descriptors from. |
CancellationToken | cancellationToken | Token that can be used to stop loading. |
Returns
Type | Description |
---|---|
Task<IEnumerable<ICommandInstanceDescriptor>> | Enumerable of all loaded command descriptors. |
Remarks
Only commands from types marked with CommandsHandlerAttribute will be loaded.
LoadFromMethodAsync(MethodInfo, CancellationToken)
Loads all command instance descriptors from a method.
Declaration
public Task<IEnumerable<ICommandInstanceDescriptor>> LoadFromMethodAsync(MethodInfo method, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
MethodInfo | method | Method to load descriptors from. |
CancellationToken | cancellationToken | Token that can be used to stop loading. |
Returns
Type | Description |
---|---|
Task<IEnumerable<ICommandInstanceDescriptor>> | Enumerable of all loaded command descriptors. |
Remarks
Commands will be loaded regardless of presence of CommandsHandlerAttribute.
Exceptions
Type | Condition |
---|---|
InvalidOperationException | No mapped initializer for a command was found. |
LoadFromTypeAsync(TypeInfo, CancellationToken)
Loads all command instance descriptors from a type.
Declaration
public Task<IEnumerable<ICommandInstanceDescriptor>> LoadFromTypeAsync(TypeInfo type, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TypeInfo | type | Type to load descriptors from. |
CancellationToken | cancellationToken | Token that can be used to stop loading. |
Returns
Type | Description |
---|---|
Task<IEnumerable<ICommandInstanceDescriptor>> | Enumerable of all loaded command descriptors. |
Remarks
Commands will be loaded regardless of presence of CommandsHandlerAttribute.