Table of Contents

Interface ISignalBuilder

Namespace
Signal.Hosting
Assembly
Signal.Hosting.dll

Fluent API returned by AddSignal() to extend Signal.NET: commands, middleware, event handlers, argument converters and receivers. Every method returns the builder for chaining.

public interface ISignalBuilder
Extension Methods

Examples

builder.AddSignal()
    .AddCommands(typeof(Program).Assembly)
    .AddEventHandlers(typeof(Program).Assembly)
    .AddMiddleware<AuditMiddleware>()
    .MapCommand("about", ctx => ctx.ReplyAsync("Signal.NET bot"));

Properties

Services

The underlying service collection, for registrations the builder does not cover.

IServiceCollection Services { get; }

Property Value

IServiceCollection

Methods

AddArgumentConverter<TConverter>()

Registers an argument converter (singleton); it overrides built-in conversion of its target type.

ISignalBuilder AddArgumentConverter<TConverter>() where TConverter : class, IArgumentConverter

Returns

ISignalBuilder

This builder.

Type Parameters

TConverter

The converter type.

AddCommandModule<TModule>()

Registers one command module.

ISignalBuilder AddCommandModule<TModule>() where TModule : CommandModule

Returns

ISignalBuilder

This builder.

Type Parameters

TModule

The module type.

AddCommand<TCommand>()

Registers one class-based command (as a scoped service).

ISignalBuilder AddCommand<TCommand>() where TCommand : class, ICommand

Returns

ISignalBuilder

This builder.

Type Parameters

TCommand

The command type.

AddCommands(Assembly)

Registers all non-abstract ICommand implementations (as scoped services) and CommandModules of an assembly.

ISignalBuilder AddCommands(Assembly assembly)

Parameters

assembly Assembly

The assembly to scan.

Returns

ISignalBuilder

This builder.

AddEventHandler<TEvent, THandler>()

Registers an event handler (scoped).

ISignalBuilder AddEventHandler<TEvent, THandler>() where TEvent : IDomainEvent where THandler : class, IEventHandler<TEvent>

Returns

ISignalBuilder

This builder.

Type Parameters

TEvent

The handled event type.

THandler

The handler type.

AddEventHandlers(Assembly)

Registers all IEventHandler<TEvent> implementations of an assembly (a class may handle several events).

ISignalBuilder AddEventHandlers(Assembly assembly)

Parameters

assembly Assembly

The assembly to scan.

Returns

ISignalBuilder

This builder.

AddMiddleware<TMiddleware>()

Adds a middleware after the built-in guards and before event dispatching and command handling. Middlewares run in registration order and are resolved per message (scoped).

ISignalBuilder AddMiddleware<TMiddleware>() where TMiddleware : class, IMessageMiddleware

Returns

ISignalBuilder

This builder.

Type Parameters

TMiddleware

The middleware type.

Configure(Action<SignalOptions>)

Configures SignalOptions in code (applied after configuration binding).

ISignalBuilder Configure(Action<SignalOptions> configure)

Parameters

configure Action<SignalOptions>

The configuration callback.

Returns

ISignalBuilder

This builder.

MapCommand(string, Func<CommandContext, Task>, string?, params string[])

Registers a lambda command, e.g. MapCommand("ping", ctx => ctx.ReplyAsync("pong")).

ISignalBuilder MapCommand(string name, Func<CommandContext, Task> handler, string? description = null, params string[] aliases)

Parameters

name string

The command name.

handler Func<CommandContext, Task>

The command body; read arguments through Arguments.

description string

One-line description for help.

aliases string[]

Alternative names.

Returns

ISignalBuilder

This builder.

UseReceiver<TReceiver>(params ExecutionMode[])

Replaces the receiver used for the given modes (all modes when none are given).

ISignalBuilder UseReceiver<TReceiver>(params ExecutionMode[] modes) where TReceiver : class, IMessageReceiver

Parameters

modes ExecutionMode[]

The modes to replace the receiver for.

Returns

ISignalBuilder

This builder.

Type Parameters

TReceiver

The receiver type (registered as transient keyed service).