API reference — Entry point
Nuvora.Nexus.Relay
Core CQRS/DDD framework for Nuvora Nexus
dotnet add package Nuvora.Nexus.Relay
Nuvora.Nexus.Relay
Relay
public static class Relay
Methods
static IServiceCollection AddCommandHandlers(this IServiceCollection services, ICommandsRegistry commandsRegistry, params Assembly[] assemblies)
Adds all command handlers from the specified assemblies
static IServiceCollection AddDomainEventHandlers(this IServiceCollection services, params Assembly[] assemblies)
Adds all domain event handlers from the specified assemblies
static IServiceCollection AddEventStoreBehaviors(this IServiceCollection services, params Assembly[] assemblies)
Adds event store behaviors from the specified assemblies
static IServiceCollection AddIntegrationEventHandlers(this IServiceCollection services, params Assembly[] assemblies)
Adds all integration event handlers from the specified assemblies
static IServiceCollection AddMessageValidators(this IServiceCollection services, params Assembly[] assemblies)
Registers all ICommandValidator/ICommandValidator and IQueryValidator/IQueryValidator implementations from the supplied assemblies as scoped services, so the validation behaviors pick them up.
static IServiceCollection AddPipelineBehaviors(this IServiceCollection services, ICommandsRegistry commandsRegistry, IQueriesRegistry queriesRegistry, params Assembly[] assemblies)
Adds all pipeline behaviors from the specified assemblies
static IServiceCollection AddQueryHandlers(this IServiceCollection services, IQueriesRegistry queriesRegistry, params Assembly[] assemblies)
Adds all query handlers from the specified assemblies
static IServiceCollection AddRelay(this IServiceCollection services, Action<RelayOptions>? configure, params Assembly[] assemblies)
Adds all handlers, validators and behaviors from the specified assemblies to the service collection, with framework options.
static IServiceCollection AddRelay(this IServiceCollection services, params Assembly[] assemblies)
Adds all handlers, validators and behaviors from the specified assemblies to the service collection
static IServiceCollection AddRelayPipelineModule(this IServiceCollection services, Assembly moduleAssembly)
Registers a module assembly that contributes pipeline behaviors (e.g. the Auth module’s authorization behaviors), independent of registration order relative to Relay.AddRelay: when AddRelay already ran, the module’s behaviors are registered immediately against the existing registries (closed over the previously scanned message assemblies); otherwise a marker is stored and AddRelay includes the assembly in its scan.
RelayAuthorizationEnforcement
public static class RelayAuthorizationEnforcement
Fail-closed startup guard for authorization. Scans every registered command/query for the Auth module’s authorization attributes ([RequireRole], [RequirePermission], [RequireClaim], [RequirePolicy], [RequireAuthentication]) and verifies the authorization pipeline behaviors are registered for each decorated message. Without this check, forgetting AddRelayAuth() silently disables every declared authorization requirement.
The check is by full type name because the Relay assembly intentionally does not reference the Auth assembly (Auth references Relay). The throw can be downgraded to a Critical log via RelayOptions.AllowUnenforcedAuthorizationAttributes.
Methods
static void Validate(ICommandsRegistry commandsRegistry, IQueriesRegistry queriesRegistry, RelayOptions options, ILogger logger)
Validates that every command/query carrying authorization attributes has the authorization behaviors in its pipeline. Throws InvalidOperationException on violation unless RelayOptions.AllowUnenforcedAuthorizationAttributes is set.
RelayOptions
public sealed class RelayOptions
Framework-level options for Relay.AddRelay.
Properties
RelayRegistrationMode RegistrationMode { get; set; }
How handlers/validators/behaviors are discovered. Defaults to RelayRegistrationMode.Generated: use compile-time generated registrations where an assembly opted into Nuvora.Nexus.Relay.Generators, and reflection-scan the rest. When no assembly has generated registrations this is identical to RelayRegistrationMode.Reflection, so existing hosts are unaffected.
bool AllowUnenforcedAuthorizationAttributes { get; set; }
Escape hatch for the fail-closed authorization startup guard. By default the host fails to start when a command/query carries authorization attributes ([RequireRole], [RequirePermission], [RequireClaim], [RequirePolicy], [RequireAuthentication]) but the authorization pipeline behaviors are not registered for it (i.e. AddRelayAuth() was never called), because the attributes would otherwise be silently ignored. Setting this to true downgrades the startup exception to a Critical log entry. Only use this deliberately — it means declared authorization requirements are NOT enforced.
bool AllowUnenforcedTenancyAttributes { get; set; }
Escape hatch for the fail-closed tenancy startup guard. By default the host fails to start when a command/query carries tenancy attributes ([TenantScoped], [GlobalOperation]) but the tenancy enforcement behavior is not registered for it (i.e. AddRelayTenancy() was never called), because the message would otherwise run without tenant isolation. Setting this to true downgrades the startup exception to a Critical log entry. Only use this deliberately — it means declared tenant scoping is NOT enforced.
RelayRegistrationMode
public enum RelayRegistrationMode
How Relay.AddRelay discovers handlers, validators and behaviors.
Values
Generated— Default. Use compile-time generated registrations (emitted byNuvora.Nexus.Relay.Generatorsinto the application assembly) where present, and fall back to reflection scanning for any assembly that has no generated module (e.g. dynamically loaded plugins, or assemblies built without the generator). When no assembly has opted into code generation this is identical toRelayRegistrationMode.Reflection.Reflection— Always reflection-scan every assembly (the original behavior). Use to force the reflection path for diagnostics, or for hosts that cannot run the generator.Hybrid— Alias ofRelayRegistrationMode.Generated: prefer generated registrations and reflection-scan the rest. Named explicitly for hosts that want the intent documented at the call site.
RelayTenancyEnforcement
public static class RelayTenancyEnforcement
Fail-closed startup guard for multi-tenancy, mirroring RelayAuthorizationEnforcement. Scans every registered command/query for the Tenancy module’s attributes ([TenantScoped], [GlobalOperation]) and verifies the tenancy enforcement behavior is registered for each decorated message. Without this check, forgetting AddRelayTenancy() would silently run a tenant-scoped message without isolation.
The check is by full type name because the Relay assembly intentionally does not reference the Tenancy assembly (Tenancy references Relay). The throw can be downgraded to a Critical log via RelayOptions.AllowUnenforcedTenancyAttributes.
Methods
static void Validate(ICommandsRegistry commandsRegistry, IQueriesRegistry queriesRegistry, RelayOptions options, ILogger logger)
Validates that every command/query carrying tenancy attributes has the tenancy enforcement behavior in its pipeline. Throws InvalidOperationException on violation unless RelayOptions.AllowUnenforcedTenancyAttributes is set.
Nuvora.Nexus.Relay.Bus
BusOperations
public static class BusOperations
Shared operations for bus implementations
Methods
static IReadOnlyList<TBehavior> ResolveBehaviors<TBehavior>(IEnumerable<Type> behaviorTypes, IServiceProvider serviceProvider, ILogger logger, string operationName)
Resolves behaviors from registry via service provider. The list is materialized once so a dispatch does not re-resolve the (transient) behaviors on every enumeration.
static Task ExecuteWithLogging(string operationName, Func<Task> operation, ILogger logger)
Executes an operation with consistent logging and exception handling (void return)
static Task<TResult> ExecuteWithLogging<TResult>(string operationName, Func<Task<TResult>> operation, ILogger logger)
Executes an operation with consistent logging and exception handling
CommandBus
public class CommandBus : ICommandBus
Interface for executing commands
Constructors
CommandBus(IServiceScopeFactory serviceScopeFactory, ICommandsRegistry commandsRegistry, IRelayScopeAccessor scopeAccessor, ILogger<CommandBus> logger, RelayTelemetryOptions? telemetryOptions = null, IRelayTenantAccessor? tenantAccessor = null)
Methods
IReadOnlyCollection<Type> GetAllCommands()
Gets the types of all registered commands
Task Execute<TCommand>(TCommand command, CancellationToken cancellationToken)
Executes a command that doesn’t return a response
Task<TResponse> Execute<TCommand, TResponse>(TCommand command, CancellationToken cancellationToken)
Executes a command that returns a response
DomainEventBus
public class DomainEventBus : EventBusBase<IDomainEvent, IDomainEventHandler<IDomainEvent>, IDomainEventsRegistry>, IDomainEventBus
Base class for event buses with shared publishing logic. Handlers are resolved and invoked by the event’s runtime type, so a handler registered for a concrete event (e.g. OrderPlaced) actually fires — dispatching by the erased marker interface (IDomainEvent) never matched any registered handler.
Constructors
DomainEventBus(IServiceScopeFactory serviceScopeFactory, IDomainEventsRegistry domainEventsRegistry, IRelayScopeAccessor scopeAccessor, ILogger<DomainEventBus> logger)
Properties
override Type HandlerOpenGenericType { get; }
The open-generic handler interface for this bus (e.g. typeof(IDomainEventHandler<>)). Used to locate the strongly-typed Handle method on a resolved handler instance.
Methods
Task Publish<TEvent>(TEvent domainEvent, CancellationToken cancellationToken)
Publishes a single domain event
Task PublishAll(IEnumerable<IDomainEvent> domainEvents, CancellationToken cancellationToken)
Publishes a heterogeneous batch of already-typed domain events, each dispatched by its runtime type. Lets the transaction behavior dispatch tracked aggregates’ events without reflection.
Task PublishMany<TEvent>(IEnumerable<TEvent> domainEvents, CancellationToken cancellationToken)
Publishes multiple domain events
override IEnumerable<Type> GetEventHandlers(Type runtimeEventType)
Gets the handler types registered for the supplied runtime event type.
EventBusBase<TEvent, THandler, TRegistry>
public abstract class EventBusBase<TEvent, THandler, TRegistry> where TEvent : class where THandler : class where TRegistry : class
Base class for event buses with shared publishing logic. Handlers are resolved and invoked by the event’s runtime type, so a handler registered for a concrete event (e.g. OrderPlaced) actually fires — dispatching by the erased marker interface (IDomainEvent) never matched any registered handler.
Constructors
EventBusBase(IServiceScopeFactory serviceScopeFactory, TRegistry registry, IRelayScopeAccessor scopeAccessor, ILogger logger)
Properties
abstract Type HandlerOpenGenericType { get; }
The open-generic handler interface for this bus (e.g. typeof(IDomainEventHandler<>)). Used to locate the strongly-typed Handle method on a resolved handler instance.
Methods
Task Publish(TEvent domainEvent, CancellationToken cancellationToken)
Publishes a single event to all handlers registered for its runtime type.
Task PublishMany(IEnumerable<TEvent> events, CancellationToken cancellationToken)
Publishes multiple events; each is dispatched by its own runtime type.
abstract IEnumerable<Type> GetEventHandlers(Type runtimeEventType)
Gets the handler types registered for the supplied runtime event type.
Fields
readonly ILogger _logger
readonly IRelayScopeAccessor _scopeAccessor
readonly IServiceScopeFactory _serviceScopeFactory
readonly TRegistry _registry
ICommandBus
public interface ICommandBus
Interface for executing commands
Methods
IReadOnlyCollection<Type> GetAllCommands()
Gets the types of all registered commands
Task Execute<TCommand>(TCommand command, CancellationToken cancellationToken)
Executes a command that doesn’t return a response
Task<TResponse> Execute<TCommand, TResponse>(TCommand command, CancellationToken cancellationToken)
Executes a command that returns a response
IDomainEventBus
public interface IDomainEventBus
Interface for publishing domain events
Methods
Task Publish<TEvent>(TEvent domainEvent, CancellationToken cancellationToken)
Publishes a single domain event
Task PublishAll(IEnumerable<IDomainEvent> domainEvents, CancellationToken cancellationToken)
Publishes a heterogeneous batch of already-typed domain events, each dispatched by its runtime type. Lets the transaction behavior dispatch tracked aggregates’ events without reflection.
Task PublishMany<TEvent>(IEnumerable<TEvent> domainEvents, CancellationToken cancellationToken)
Publishes multiple domain events
IIntegrationEventBus
public interface IIntegrationEventBus
Methods
Task DispatchToLocalHandlers(IIntegrationEvent integrationEvent, CancellationToken cancellationToken)
Dispatches an integration event received from the broker to this service’s local IIntegrationEventHandlers (the inbox consume path), as opposed to IIntegrationEventBus.Publish which enqueues an outgoing event on the outbox.
Task Publish<TEvent>(TEvent integrationEvent, CancellationToken cancellationToken)
Task PublishMany<TEvent>(IEnumerable<TEvent> integrationEvents, CancellationToken cancellationToken)
IQueryBus
public interface IQueryBus
Interface for executing queries
Methods
Task<TResponse> Execute<TQuery, TResponse>(TQuery query, CancellationToken cancellationToken)
Executes a query and returns the response
IRelayScopeAccessor
public interface IRelayScopeAccessor
Exposes the DI scope of the command currently executing on this async flow, so the domain- and integration-event buses can resolve their dependencies (handlers, outbox repository) from the same scope — and therefore the same DbContext/transaction — as the command’s unit of work, instead of spinning up a disconnected scope whose writes are silently lost.
Properties
IServiceProvider? Current { get; }
The service provider of the ambient command scope, or null outside a command.
Methods
IDisposable Enter(IServiceProvider scopeProvider)
Sets the ambient command scope for the duration of the returned token. Disposing the token restores the previous value (scopes nest correctly across nested command dispatch).
IntegrationEventBus
public class IntegrationEventBus : EventBusBase<IIntegrationEvent, IIntegrationEventHandler<IIntegrationEvent>, IIntegrationEventsRegistry>, IIntegrationEventBus
Publishes integration events through the transactional outbox. The outbox row is written on the command’s DI scope (via IRelayScopeAccessor), so it stages onto the same DbContext as the aggregate state and commits atomically with it — no dual-write, no disconnected-scope loss. Actual broker delivery is owned by the outbox processor.
Constructors
IntegrationEventBus(IServiceScopeFactory serviceScopeFactory, IIntegrationEventsRegistry integrationEventsRegistry, IRelayScopeAccessor scopeAccessor, ILogger<IntegrationEventBus> logger)
Properties
override Type HandlerOpenGenericType { get; }
The open-generic handler interface for this bus (e.g. typeof(IDomainEventHandler<>)). Used to locate the strongly-typed Handle method on a resolved handler instance.
Methods
Task DispatchToLocalHandlers(IIntegrationEvent integrationEvent, CancellationToken cancellationToken)
Dispatches an integration event received from the broker to this service’s local IIntegrationEventHandlers (the inbox consume path), as opposed to IIntegrationEventBus.Publish which enqueues an outgoing event on the outbox.
Task Publish<TEvent>(TEvent integrationEvent, CancellationToken cancellationToken)
Task PublishMany<TEvent>(IEnumerable<TEvent> integrationEvents, CancellationToken cancellationToken)
override IEnumerable<Type> GetEventHandlers(Type runtimeEventType)
Gets the handler types registered for the supplied runtime event type.
QueryBus
public class QueryBus : IQueryBus
Interface for executing queries
Constructors
QueryBus(IServiceScopeFactory serviceScopeFactory, IQueriesRegistry queriesRegistry, ILogger<QueryBus> logger, IOptions<RelayTelemetryOptions>? telemetryOptions = null, IRelayTenantAccessor? tenantAccessor = null)
Methods
Task<TResponse> Execute<TQuery, TResponse>(TQuery query, CancellationToken cancellationToken)
Executes a query and returns the response
RelayScopeAccessor
public sealed class RelayScopeAccessor : IRelayScopeAccessor
AsyncLocal-backed implementation of IRelayScopeAccessor. Registered as a singleton; the ambient value flows with the async execution context of each command.
Properties
IServiceProvider? Current { get; }
The service provider of the ambient command scope, or null outside a command.
Methods
IDisposable Enter(IServiceProvider scopeProvider)
Sets the ambient command scope for the duration of the returned token. Disposing the token restores the previous value (scopes nest correctly across nested command dispatch).
Nuvora.Nexus.Relay.Bus.Behaviors
AutomaticBehaviorAttribute
public class AutomaticBehaviorAttribute : Attribute
Marker attribute for automatic pipeline behaviors that are applied to all messages
Constructors
AutomaticBehaviorAttribute(int priority = 0)
Properties
int Priority { get; }
Priority for execution order. Lower values execute earlier.
CacheableAttribute
public class CacheableAttribute : PipelineBehaviorAttribute
Attribute to mark commands/queries as cacheable
Properties
int DurationSeconds { get; set; }
Cache duration in seconds
LoggingBehavior<TCommand, TResponse>
public class LoggingBehavior<TCommand, TResponse> : ICommandPipelineBehavior<TCommand, TResponse> where TCommand : ICommand<TResponse>
Pipeline behavior that logs command execution with timing
Constructors
LoggingBehavior(ILogger<LoggingBehavior<TCommand, TResponse>> logger)
Methods
Task<TResponse> Handle(TCommand command, CancellationToken cancellationToken, Func<TCommand, CancellationToken, Task<TResponse>> next)
LoggingBehavior<TCommand>
public class LoggingBehavior<TCommand> : ICommandPipelineBehavior<TCommand> where TCommand : ICommand
Pipeline behavior that logs command execution with timing (void commands)
Constructors
LoggingBehavior(ILogger<LoggingBehavior<TCommand>> logger)
Methods
Task Handle(TCommand command, CancellationToken cancellationToken, Func<TCommand, CancellationToken, Task> next)
PipelineBehaviorAttribute
public abstract class PipelineBehaviorAttribute : Attribute
Base attribute for attribute-based pipeline behaviors
Properties
int Priority { get; set; }
Priority for execution order. Lower values execute earlier.
QueryCachingBehavior<TQuery, TResponse>
public class QueryCachingBehavior<TQuery, TResponse> : IQueryPipelineBehavior<TQuery, TResponse> where TQuery : IQuery<TResponse>
Pipeline behavior for caching query results
Constructors
QueryCachingBehavior(ILogger<QueryCachingBehavior<TQuery, TResponse>> logger, ICachingStrategy cachingStrategy, ITenantCacheKeyProvider? tenantCacheKey = null)
Methods
Task<TResponse> Handle(TQuery query, CancellationToken cancellationToken, Func<TQuery, CancellationToken, Task<TResponse>> next)
QueryLoggingBehavior<TQuery, TResponse>
public class QueryLoggingBehavior<TQuery, TResponse> : IQueryPipelineBehavior<TQuery, TResponse> where TQuery : IQuery<TResponse>
Pipeline behavior that logs query execution with timing
Constructors
QueryLoggingBehavior(ILogger<QueryLoggingBehavior<TQuery, TResponse>> logger)
Methods
Task<TResponse> Handle(TQuery query, CancellationToken cancellationToken, Func<TQuery, CancellationToken, Task<TResponse>> next)
QueryValidationBehavior<TQuery, TResponse>
public class QueryValidationBehavior<TQuery, TResponse> : IQueryPipelineBehavior<TQuery, TResponse> where TQuery : IQuery<TResponse>
Pipeline behavior for query validation
Constructors
QueryValidationBehavior(IServiceProvider serviceProvider, ILogger<QueryValidationBehavior<TQuery, TResponse>> logger)
Methods
Task<TResponse> Handle(TQuery query, CancellationToken cancellationToken, Func<TQuery, CancellationToken, Task<TResponse>> next)
TransactionBehavior<TCommand, TResponse>
public class TransactionBehavior<TCommand, TResponse> : ICommandPipelineBehavior<TCommand, TResponse> where TCommand : ICommand<TResponse>
Pipeline behavior that runs a command inside a database transaction, then persists and dispatches the events of any tracked aggregates atomically with the command’s state changes. The work is delegated to TransactionExecutor so both the response and void variants share one implementation. Commands marked with SkipTransactionAttribute bypass the transactional pipeline entirely (and do not require IUnitOfWork or the event store to be registered); dependencies are resolved lazily from the command scope so the skip path has no DI requirements.
Constructors
TransactionBehavior(IServiceProvider serviceProvider, ILogger<TransactionBehavior<TCommand, TResponse>> logger)
Methods
Task<TResponse> Handle(TCommand command, CancellationToken cancellationToken, Func<TCommand, CancellationToken, Task<TResponse>> next)
TransactionBehavior<TCommand>
public class TransactionBehavior<TCommand> : ICommandPipelineBehavior<TCommand> where TCommand : ICommand
Transaction behavior for void commands. See TransactionBehavior.
Constructors
TransactionBehavior(IServiceProvider serviceProvider, ILogger<TransactionBehavior<TCommand>> logger)
Methods
Task Handle(TCommand command, CancellationToken cancellationToken, Func<TCommand, CancellationToken, Task> next)
TriggeredByMessageAttribute
public sealed class TriggeredByMessageAttribute : Attribute
Declares that an attribute-based pipeline behavior should run for a message only when the message carries the given attribute (e.g. QueryCachingBehavior is triggered by CacheableAttribute). Replaces brittle behavior-name string matching in the pipeline filter with an explicit, type-safe link.
Constructors
TriggeredByMessageAttribute(Type messageAttributeType)
Properties
Type MessageAttributeType { get; }
The message attribute whose presence activates the behavior.
ValidationBehavior<TCommand, TResponse>
public class ValidationBehavior<TCommand, TResponse> : ICommandPipelineBehavior<TCommand, TResponse> where TCommand : ICommand<TResponse>
Pipeline behavior for command validation. All registered validators run and their failures are aggregated into a single ValidationException, so callers see every error at once instead of fixing them one validator at a time.
Constructors
ValidationBehavior(IServiceProvider serviceProvider, ILogger<ValidationBehavior<TCommand, TResponse>> logger)
Methods
Task<TResponse> Handle(TCommand command, CancellationToken cancellationToken, Func<TCommand, CancellationToken, Task<TResponse>> next)
ValidationBehavior<TCommand>
public class ValidationBehavior<TCommand> : ICommandPipelineBehavior<TCommand> where TCommand : ICommand
Pipeline behavior for command validation (void commands)
Constructors
ValidationBehavior(IServiceProvider serviceProvider, ILogger<ValidationBehavior<TCommand>> logger)
Methods
Task Handle(TCommand command, CancellationToken cancellationToken, Func<TCommand, CancellationToken, Task> next)
ValidationException
public class ValidationException : Exception
Exception thrown when validation fails
Constructors
ValidationException(string message, IList<ValidationFailure> errors)
Properties
IList<ValidationFailure> Errors { get; }
Nuvora.Nexus.Relay.Bus.Pipelines
CommandPipeline<TCommand, TResult>
public class CommandPipeline<TCommand, TResult> where TCommand : ICommand<TResult>
Constructors
CommandPipeline(IEnumerable<ICommandPipelineBehavior<TCommand, TResult>> behaviors, ICommandHandler<TCommand, TResult> handler)
Methods
Task<TResult> ExecuteAsync(TCommand command, CancellationToken cancellationToken)
CommandPipeline<TCommand>
public class CommandPipeline<TCommand> where TCommand : ICommand
Constructors
CommandPipeline(IEnumerable<ICommandPipelineBehavior<TCommand>> behaviors, ICommandHandler<TCommand> handler)
Methods
Task ExecuteAsync(TCommand command, CancellationToken cancellationToken)
PipelineBehaviorFilter
public static class PipelineBehaviorFilter
Shared utility for filtering and ordering pipeline behaviors. Selection rules:
- [AutomaticBehavior] — runs for every message (its Priority orders it).
- [TriggeredByMessage] — runs only when the message carries the matching attribute.
- No attributes — treated as automatic: the behavior was explicitly written and registered, so silently dropping it (the old rule) violated least surprise.
A behavior carrying both attributes runs at most once (deduplicated by type). Attribute lookups are cached per (messageType, behaviorType) because this runs on every dispatch.
Methods
static IReadOnlyList<TBehavior> FilterAndOrderBehaviors<TBehavior>(IEnumerable<TBehavior> behaviors, Type messageType)
Filters and orders behaviors based on automatic attributes and message attributes
static bool HasAutomaticBehaviorAttribute(Type behaviorType)
Checks if a behavior type has the AutomaticBehaviorAttribute
static bool MessageHasMatchingAttribute(Type messageType, Type behaviorType)
Checks if a message type carries an attribute that activates the behavior, as declared by the behavior’s TriggeredByMessageAttribute(s).
static int GetBehaviorPriority(Type behaviorType)
Gets the priority of a behavior type for ordering
QueryPipeline<TQuery, TResult>
public class QueryPipeline<TQuery, TResult> where TQuery : IQuery<TResult>
Constructors
QueryPipeline(IEnumerable<IQueryPipelineBehavior<TQuery, TResult>> behaviors, IQueryHandler<TQuery, TResult> handler)
Methods
Task<TResult> ExecuteAsync(TQuery query, CancellationToken cancellationToken)
Nuvora.Nexus.Relay.Bus.Registries
CommandsRegistry
public class CommandsRegistry : ICommandsRegistry
In-memory registry for command handlers and pipeline behaviors with caching
Methods
IEnumerable<Type> GetAllCommands()
Gets all registered command types
IEnumerable<Type> GetPipelineBehaviors(Type commandType)
Gets all pipeline behaviors for the specified command type (no response, non-generic)
IEnumerable<Type> GetPipelineBehaviors(Type commandType, Type responseType)
Gets all pipeline behaviors for the specified command type (non-generic)
IEnumerable<Type> GetPipelineBehaviors<TCommand, TResponse>()
Gets all pipeline behaviors for the specified command type
IEnumerable<Type> GetPipelineBehaviors<TCommand>()
Gets all pipeline behaviors for the specified command type (no response)
Type? GetCommandHandler<TCommand, TResponse>()
Gets a command handler for the specified command type
Type? GetCommandHandler<TCommand>()
Gets a command handler for the specified command type (no response)
void RegisterCommandHandler(Type commandType, Type handlerType)
Registers a command handler
void RegisterPipelineBehavior(Type behaviorType)
Registers a pipeline behavior
DomainEventsRegistry
public class DomainEventsRegistry : IDomainEventsRegistry
In-memory registry for domain event handlers with caching
Methods
IEnumerable<Type> GetAllDomainEvents()
Gets all registered domain event types
IEnumerable<Type> GetEventHandlers(Type eventType)
Gets all handlers registered for the specified (concrete) domain event type. Used to dispatch by the event’s runtime type rather than a marker interface.
IEnumerable<Type> GetEventHandlers<TEvent>()
Gets all handlers for the specified domain event type
void RegisterEventHandler(Type eventType, Type handlerType)
Registers a domain event handler
ICommandsRegistry
public interface ICommandsRegistry
Registry for command handlers and pipeline behaviors
Methods
IEnumerable<Type> GetAllCommands()
Gets all registered command types
IEnumerable<Type> GetPipelineBehaviors(Type commandType)
Gets all pipeline behaviors for the specified command type (no response, non-generic)
IEnumerable<Type> GetPipelineBehaviors(Type commandType, Type responseType)
Gets all pipeline behaviors for the specified command type (non-generic)
IEnumerable<Type> GetPipelineBehaviors<TCommand, TResponse>()
Gets all pipeline behaviors for the specified command type
IEnumerable<Type> GetPipelineBehaviors<TCommand>()
Gets all pipeline behaviors for the specified command type (no response)
Type? GetCommandHandler<TCommand, TResponse>()
Gets a command handler for the specified command type
Type? GetCommandHandler<TCommand>()
Gets a command handler for the specified command type (no response)
void RegisterCommandHandler(Type commandType, Type handlerType)
Registers a command handler
void RegisterPipelineBehavior(Type behaviorType)
Registers a pipeline behavior
IDomainEventsRegistry
public interface IDomainEventsRegistry
Registry for domain event handlers
Methods
IEnumerable<Type> GetAllDomainEvents()
Gets all registered domain event types
IEnumerable<Type> GetEventHandlers(Type eventType)
Gets all handlers registered for the specified (concrete) domain event type. Used to dispatch by the event’s runtime type rather than a marker interface.
IEnumerable<Type> GetEventHandlers<TEvent>()
Gets all handlers for the specified domain event type
void RegisterEventHandler(Type eventType, Type handlerType)
Registers a domain event handler
IIntegrationEventsRegistry
public interface IIntegrationEventsRegistry
Registry for integration event handlers
Methods
IEnumerable<Type> GetAllIntegrationEvents()
Gets all registered integration event types
IEnumerable<Type> GetEventHandlers(Type eventType)
Gets all handlers registered for the specified (concrete) integration event type. Used to dispatch by the event’s runtime type rather than a marker interface.
IEnumerable<Type> GetEventHandlers<TEvent>()
Gets all handlers for the specified integration event type
void RegisterEventHandler(Type eventType, Type handlerType)
Registers an integration event handler
IQueriesRegistry
public interface IQueriesRegistry
Registry for query handlers and pipeline behaviors
Methods
IEnumerable<Type> GetAllQueries()
Gets all registered query types
IEnumerable<Type> GetPipelineBehaviors(Type queryType, Type responseType)
Gets all pipeline behaviors for the specified query type (non-generic)
IEnumerable<Type> GetPipelineBehaviors<TQuery, TResponse>()
Gets all pipeline behaviors for the specified query type
Type? GetQueryHandler<TQuery, TResponse>()
Gets a query handler for the specified query type
void RegisterPipelineBehavior(Type behaviorType)
Registers a pipeline behavior
void RegisterQueryHandler(Type queryType, Type handlerType)
Registers a query handler
IntegrationEventsRegistry
public class IntegrationEventsRegistry : IIntegrationEventsRegistry
In-memory registry for integration event handlers with caching
Methods
IEnumerable<Type> GetAllIntegrationEvents()
Gets all registered integration event types
IEnumerable<Type> GetEventHandlers(Type eventType)
Gets all handlers registered for the specified (concrete) integration event type. Used to dispatch by the event’s runtime type rather than a marker interface.
IEnumerable<Type> GetEventHandlers<TEvent>()
Gets all handlers for the specified integration event type
void RegisterEventHandler(Type eventType, Type handlerType)
Registers an integration event handler
QueriesRegistry
public class QueriesRegistry : IQueriesRegistry
In-memory registry for query handlers and pipeline behaviors with caching
Methods
IEnumerable<Type> GetAllQueries()
Gets all registered query types
IEnumerable<Type> GetPipelineBehaviors(Type queryType, Type responseType)
Gets all pipeline behaviors for the specified query type (non-generic)
IEnumerable<Type> GetPipelineBehaviors<TQuery, TResponse>()
Gets all pipeline behaviors for the specified query type
Type? GetQueryHandler<TQuery, TResponse>()
Gets a query handler for the specified query type
void RegisterPipelineBehavior(Type behaviorType)
Registers a pipeline behavior
void RegisterQueryHandler(Type queryType, Type handlerType)
Registers a query handler
Nuvora.Nexus.Relay.Generation
IRelayGeneratedModule
public interface IRelayGeneratedModule
Implemented by the source generator’s per-assembly registration class (one per application assembly). Its IRelayGeneratedModule.Register performs the same DI + registry population the reflection path does, but with direct typeof(...) references (no runtime type scanning). The generated class registers itself into RelayGeneratedRegistry from a [ModuleInitializer], which runs when the assembly loads, so AddRelay can consume it without reflection.
Properties
string AssemblyName { get; }
The simple name of the assembly this module covers.
Methods
void Register(RelayGeneratedRegistrationContext context)
Populates DI and the command/query registries for this assembly’s handlers and behaviors.
RelayGeneratedRegistrationContext
public sealed class RelayGeneratedRegistrationContext
The surface a generated module registers against.
Properties
ICommandsRegistry Commands { get; }
IQueriesRegistry Queries { get; }
IServiceCollection Services { get; }
RelayGeneratedRegistry
public static class RelayGeneratedRegistry
Process-wide registry of generated registration modules. Generated code pushes a module here from a [ModuleInitializer] when its assembly loads; AddRelay consumes the modules for the assemblies it was asked to scan (and reflection-scans the rest). Thread-safe and idempotent.
Methods
static IReadOnlyList<IRelayGeneratedModule> GetModulesFor(IEnumerable<Assembly> assemblies)
Returns the generated modules covering any of the supplied assemblies.
static void Register(IRelayGeneratedModule module)
Registers a generated module (no-op if one for the same assembly is already present).
Nuvora.Nexus.Relay.Inbox
InboxOptions
public sealed class InboxOptions
Options for the inbox consumer. Each service consumes into its own durable queue, bound to the shared topic exchange by one or more routing keys (default # = everything).
Properties
bool Enabled { get; set; }
Whether the inbox consumer is enabled.
double SubscribeRetryBaseDelaySeconds { get; set; }
Base delay for the exponential backoff used when an initial subscribe fails (e.g. the broker is down at startup). The consumer keeps retrying — capped at InboxOptions.SubscribeRetryMaxDelaySeconds — until it connects or the service shuts down, so a broker outage no longer needs a restart.
double SubscribeRetryMaxDelaySeconds { get; set; }
Upper bound on the subscribe-retry backoff delay.
string QueueName { get; set; }
Durable queue name this service consumes from. Must be unique per logical service.
string[] RoutingKeys { get; set; }
Topic routing keys to bind (e.g. "order.*"). Empty binds # (all).
InboxProcessor
public sealed class InboxProcessor : BackgroundService
Hosted service implementing the inbox pattern: subscribes to the broker and, for each delivered integration event, processes it exactly once. Per message it opens a command scope (so handlers share one DbContext/transaction), skips already-processed messages via IInboxRepository, deserializes through the event-type registry/upcasters, dispatches to local IIntegrationEventHandlers, records the dedup row, and commits — all atomically. A failure rolls everything back and the message is redelivered.
Constructors
InboxProcessor(IMessageConsumer consumer, IServiceScopeFactory scopeFactory, IRelayScopeAccessor scopeAccessor, IOptions<InboxOptions> options, ILogger<InboxProcessor> logger, IListenerRegistry? listeners = null)
Methods
override Task ExecuteAsync(CancellationToken stoppingToken)
This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.
InboxServiceCollectionExtensions
public static class InboxServiceCollectionExtensions
Registration helper for the inbox consumer. Requires a message consumer (e.g. AddRelayRabbitMq), an inbox repository (AddRelayInboxEfCore) and a unit of work.
Methods
static IServiceCollection AddRelayInbox(this IServiceCollection services, Action<InboxOptions>? configure = null)