Class InProcessBus<TAuthenticationToken>
An in process command bus (ICommandPublisher<TAuthenticationToken> and ICommandReceiver<TAuthenticationToken>) event bus (IEventPublisher<TAuthenticationToken> and IEventHandler<TAuthenticationToken, TTarget, TEvent>) as well as a IEventHandlerRegistrar and ICommandHandlerRegistrar that requires no networking.
Inheritance
Inherited Members
Namespace: Cqrs.Bus
Assembly: Cqrs.dll
Syntax
public class InProcessBus<TAuthenticationToken> : IPublishAndWaitCommandPublisher<TAuthenticationToken>, ICommandPublisher<TAuthenticationToken>, IEventPublisher<TAuthenticationToken>, IEventHandlerRegistrar, ICommandHandlerRegistrar, IHandlerRegistrar, ICommandReceiver<TAuthenticationToken>, ICommandReceiver, IEventReceiver<TAuthenticationToken>, IEventReceiver
Type Parameters
Name | Description |
---|---|
TAuthenticationToken | The System.Type of the authentication token. |
Constructors
InProcessBus(IAuthenticationTokenHelper<TAuthenticationToken>, ICorrelationIdHelper, IDependencyResolver, ILogger, IConfigurationManager, IBusHelper)
Instantiates a new instance of the InProcessBus<TAuthenticationToken> class.
Declaration
public InProcessBus(IAuthenticationTokenHelper<TAuthenticationToken> authenticationTokenHelper, ICorrelationIdHelper correlationIdHelper, IDependencyResolver dependencyResolver, ILogger logger, IConfigurationManager configurationManager, IBusHelper busHelper)
Parameters
Type | Name | Description |
---|---|---|
IAuthenticationTokenHelper<TAuthenticationToken> | authenticationTokenHelper | |
cdmdotnet.Logging.ICorrelationIdHelper | correlationIdHelper | |
IDependencyResolver | dependencyResolver | |
cdmdotnet.Logging.ILogger | logger | |
IConfigurationManager | configurationManager | |
IBusHelper | busHelper |
Properties
AuthenticationTokenHelper
Gets or sets the Authentication Token Helper
Declaration
protected IAuthenticationTokenHelper<TAuthenticationToken> AuthenticationTokenHelper { get; }
Property Value
Type | Description |
---|---|
IAuthenticationTokenHelper<TAuthenticationToken> |
BusHelper
Gets or sets the Bus Helper
Declaration
protected IBusHelper BusHelper { get; }
Property Value
Type | Description |
---|---|
IBusHelper |
ConfigurationManager
Gets or sets the Configuration Manager
Declaration
protected IConfigurationManager ConfigurationManager { get; }
Property Value
Type | Description |
---|---|
IConfigurationManager |
CorrelationIdHelper
Gets or sets the CorrelationId Helper
Declaration
protected ICorrelationIdHelper CorrelationIdHelper { get; }
Property Value
Type | Description |
---|---|
cdmdotnet.Logging.ICorrelationIdHelper |
DependencyResolver
Gets or sets the Dependency Resolver
Declaration
protected IDependencyResolver DependencyResolver { get; }
Property Value
Type | Description |
---|---|
IDependencyResolver |
EventWaits
Gets or sets the current list of events waiting to be evaluated for PublishAndWait<TCommand, TEvent>(TCommand, IEventReceiver<TAuthenticationToken>)
Declaration
protected IDictionary<Guid, IList<IEvent<TAuthenticationToken>>> EventWaits { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.Guid, System.Collections.Generic.IList<IEvent<TAuthenticationToken>>> |
Logger
Gets or sets the Logger
Declaration
protected ILogger Logger { get; }
Property Value
Type | Description |
---|---|
cdmdotnet.Logging.ILogger |
TelemetryHelper
Gets or sets the Telemetry Helper
Declaration
protected ITelemetryHelper TelemetryHelper { get; set; }
Property Value
Type | Description |
---|---|
cdmdotnet.Logging.ITelemetryHelper |
Methods
PrepareAndValidateCommand<TCommand>(TCommand, out RouteHandlerDelegate)
Locates a suitable ICommandValidator<TAuthenticationToken, TCommand> to validate the provided command
and validates the provided command
if one is located
Calls PrepareCommand<TCommand>(TCommand)
Checks if the provided command
is required to be processed
Locates a single RouteHandlerDelegate for the provided command
Declaration
protected virtual bool PrepareAndValidateCommand<TCommand>(TCommand command, out RouteHandlerDelegate commandHandler)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | |
RouteHandlerDelegate | commandHandler |
Returns
Type | Description |
---|---|
System.Boolean | False if a suitable ICommandValidator<TAuthenticationToken, TCommand> is located and the provided |
Type Parameters
Name | Description |
---|---|
TCommand |
PrepareCommand<TCommand>(TCommand)
Sets the AuthenticationToken, CorrelationId, OriginatingFramework to "Built-In" and adds a value of "Built-In" to the Frameworks if not already done so
Declaration
protected virtual void PrepareCommand<TCommand>(TCommand command)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command |
Type Parameters
Name | Description |
---|---|
TCommand |
Publish<TEvent>(TEvent)
Publishes the provided event
on the event bus.
Declaration
public virtual void Publish<TEvent>(TEvent event)where TEvent : IEvent<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TEvent | event |
Type Parameters
Name | Description |
---|---|
TEvent |
Implements
Publish<TEvent>(IEnumerable<TEvent>)
Publishes the provided events
on the event bus.
Declaration
public virtual void Publish<TEvent>(IEnumerable<TEvent> events)where TEvent : IEvent<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TEvent> | events |
Type Parameters
Name | Description |
---|---|
TEvent |
Implements
PublishAndWait<TCommand, TEvent>(TCommand, IEventReceiver<TAuthenticationToken>)
Publishes the provided command
and waits for an event of TEvent
Declaration
public TEvent PublishAndWait<TCommand, TEvent>(TCommand command, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
Implements
PublishAndWait<TCommand, TEvent>(TCommand, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent>, IEventReceiver<TAuthenticationToken>)
Publishes the provided command
and waits until the specified condition is satisfied an event of TEvent
Declaration
public TEvent PublishAndWait<TCommand, TEvent>(TCommand command, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent> condition, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
System.Func<System.Collections.Generic.IEnumerable<IEvent<TAuthenticationToken>>, TEvent> | condition | A delegate to be executed over and over until it returns the |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
Implements
PublishAndWait<TCommand, TEvent>(TCommand, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent>, Int32, IEventReceiver<TAuthenticationToken>)
Publishes the provided command
and waits for an event of TEvent
or exits if the specified timeout is expired.
Declaration
public TEvent PublishAndWait<TCommand, TEvent>(TCommand command, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent> condition, int millisecondsTimeout, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
System.Func<System.Collections.Generic.IEnumerable<IEvent<TAuthenticationToken>>, TEvent> | condition | A delegate to be executed over and over until it returns the |
System.Int32 | millisecondsTimeout | The number of milliseconds to wait, or System.Threading.Timeout.Infinite (-1) to wait indefinitely. |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
Implements
PublishAndWait<TCommand, TEvent>(TCommand, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent>, TimeSpan, IEventReceiver<TAuthenticationToken>)
Publishes the provided command
and waits for an event of TEvent
or exits if the specified timeout is expired.
Declaration
public TEvent PublishAndWait<TCommand, TEvent>(TCommand command, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent> condition, TimeSpan timeout, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
System.Func<System.Collections.Generic.IEnumerable<IEvent<TAuthenticationToken>>, TEvent> | condition | A delegate to be executed over and over until it returns the |
System.TimeSpan | timeout | A System.TimeSpan that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely. |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
Implements
PublishAndWait<TCommand, TEvent>(TCommand, Int32, IEventReceiver<TAuthenticationToken>)
Publishes the provided command
and waits for an event of TEvent
or exits if the specified timeout is expired.
Declaration
public TEvent PublishAndWait<TCommand, TEvent>(TCommand command, int millisecondsTimeout, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
System.Int32 | millisecondsTimeout | The number of milliseconds to wait, or System.Threading.Timeout.Infinite (-1) to wait indefinitely. |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
Implements
PublishAndWait<TCommand, TEvent>(TCommand, TimeSpan, IEventReceiver<TAuthenticationToken>)
Publishes the provided command
and waits for an event of TEvent
or exits if the specified timeout is expired.
Declaration
public TEvent PublishAndWait<TCommand, TEvent>(TCommand command, TimeSpan timeout, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
System.TimeSpan | timeout | A System.TimeSpan that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely. |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
Implements
ReceiveCommand(ICommand<TAuthenticationToken>)
Receives a ICommand<TAuthenticationToken> from the command bus.
Declaration
public virtual bool ? ReceiveCommand(ICommand<TAuthenticationToken> command)
Parameters
Type | Name | Description |
---|---|---|
ICommand<TAuthenticationToken> | command |
Returns
Type | Description |
---|---|
System.Nullable<System.Boolean> |
Implements
ReceiveEvent(IEvent<TAuthenticationToken>)
Receives an IEvent<TAuthenticationToken> from the event bus.
Declaration
public virtual bool ? ReceiveEvent(IEvent<TAuthenticationToken> event)
Parameters
Type | Name | Description |
---|---|---|
IEvent<TAuthenticationToken> | event |
Returns
Type | Description |
---|---|
System.Nullable<System.Boolean> |
Implements
RegisterGlobalEventHandler<TMessage>(Action<TMessage>, Boolean)
Register an event handler that will listen and respond to all events.
Declaration
public void RegisterGlobalEventHandler<TMessage>(Action<TMessage> handler, bool holdMessageLock = true)where TMessage : IMessage
Parameters
Type | Name | Description |
---|---|---|
System.Action<TMessage> | handler | |
System.Boolean | holdMessageLock |
Type Parameters
Name | Description |
---|---|
TMessage |
Implements
RegisterHandler<TMessage>(Action<TMessage>, Boolean)
Register an event or command handler that will listen and respond to events or commands.
Declaration
public virtual void RegisterHandler<TMessage>(Action<TMessage> handler, bool holdMessageLock = true)where TMessage : IMessage
Parameters
Type | Name | Description |
---|---|---|
System.Action<TMessage> | handler | |
System.Boolean | holdMessageLock |
Type Parameters
Name | Description |
---|---|
TMessage |
Implements
RegisterHandler<TMessage>(Action<TMessage>, Type, Boolean)
Register an event or command handler that will listen and respond to events or commands.
Declaration
public virtual void RegisterHandler<TMessage>(Action<TMessage> handler, Type targetedType, bool holdMessageLock = true)where TMessage : IMessage
Parameters
Type | Name | Description |
---|---|---|
System.Action<TMessage> | handler | |
System.Type | targetedType | |
System.Boolean | holdMessageLock |
Type Parameters
Name | Description |
---|---|
TMessage |
Implements
Send<TCommand>(TCommand)
Publishes the provided command
on the command bus.
Declaration
public virtual void Send<TCommand>(TCommand command)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command |
Type Parameters
Name | Description |
---|---|
TCommand |
Send<TCommand>(IEnumerable<TCommand>)
Publishes the provided commands
on the command bus.
Declaration
public virtual void Send<TCommand>(IEnumerable<TCommand> commands)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TCommand> | commands |
Type Parameters
Name | Description |
---|---|
TCommand |
SendAndWait<TCommand, TEvent>(TCommand, IEventReceiver<TAuthenticationToken>)
Sends the provided command
and waits for an event of TEvent
Declaration
public virtual TEvent SendAndWait<TCommand, TEvent>(TCommand command, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
SendAndWait<TCommand, TEvent>(TCommand, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent>, IEventReceiver<TAuthenticationToken>)
Sends the provided command
and waits until the specified condition is satisfied an event of TEvent
Declaration
public virtual TEvent SendAndWait<TCommand, TEvent>(TCommand command, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent> condition, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
System.Func<System.Collections.Generic.IEnumerable<IEvent<TAuthenticationToken>>, TEvent> | condition | A delegate to be executed over and over until it returns the |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
SendAndWait<TCommand, TEvent>(TCommand, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent>, Int32, IEventReceiver<TAuthenticationToken>)
Sends the provided command
and waits for an event of TEvent
or exits if the specified timeout is expired.
Declaration
public virtual TEvent SendAndWait<TCommand, TEvent>(TCommand command, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent> condition, int millisecondsTimeout, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
System.Func<System.Collections.Generic.IEnumerable<IEvent<TAuthenticationToken>>, TEvent> | condition | A delegate to be executed over and over until it returns the |
System.Int32 | millisecondsTimeout | The number of milliseconds to wait, or System.Threading.Timeout.Infinite (-1) to wait indefinitely. |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
SendAndWait<TCommand, TEvent>(TCommand, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent>, TimeSpan, IEventReceiver<TAuthenticationToken>)
Sends the provided command
and waits for an event of TEvent
or exits if the specified timeout is expired.
Declaration
public virtual TEvent SendAndWait<TCommand, TEvent>(TCommand command, Func<IEnumerable<IEvent<TAuthenticationToken>>, TEvent> condition, TimeSpan timeout, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
System.Func<System.Collections.Generic.IEnumerable<IEvent<TAuthenticationToken>>, TEvent> | condition | A delegate to be executed over and over until it returns the |
System.TimeSpan | timeout | A System.TimeSpan that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely. |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
SendAndWait<TCommand, TEvent>(TCommand, Int32, IEventReceiver<TAuthenticationToken>)
Sends the provided command
and waits for an event of TEvent
or exits if the specified timeout is expired.
Declaration
public virtual TEvent SendAndWait<TCommand, TEvent>(TCommand command, int millisecondsTimeout, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
System.Int32 | millisecondsTimeout | The number of milliseconds to wait, or System.Threading.Timeout.Infinite (-1) to wait indefinitely. |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
SendAndWait<TCommand, TEvent>(TCommand, TimeSpan, IEventReceiver<TAuthenticationToken>)
Sends the provided command
and waits for an event of TEvent
or exits if the specified timeout is expired.
Declaration
public virtual TEvent SendAndWait<TCommand, TEvent>(TCommand command, TimeSpan timeout, IEventReceiver<TAuthenticationToken> eventReceiver = null)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The |
System.TimeSpan | timeout | A System.TimeSpan that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely. |
IEventReceiver<TAuthenticationToken> | eventReceiver | If provided, is the IEventReceiver<TAuthenticationToken> that the event is expected to be returned on. |
Returns
Type | Description |
---|---|
TEvent |
Type Parameters
Name | Description |
---|---|
TCommand | |
TEvent |
Explicit Interface Implementations
ICommandPublisher<TAuthenticationToken>.Publish<TCommand>(TCommand)
Publishes the provided command
on the command bus.
Declaration
void ICommandPublisher<TAuthenticationToken>.Publish<TCommand>(TCommand command)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command |
Type Parameters
Name | Description |
---|---|
TCommand |
Implements
ICommandPublisher<TAuthenticationToken>.Publish<TCommand>(IEnumerable<TCommand>)
Publishes the provided commands
on the command bus.
Declaration
void ICommandPublisher<TAuthenticationToken>.Publish<TCommand>(IEnumerable<TCommand> commands)where TCommand : ICommand<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TCommand> | commands |
Type Parameters
Name | Description |
---|---|
TCommand |
Implements
ICommandReceiver.Start()
Declaration
void ICommandReceiver.Start()
Implements
IEventReceiver.Start()
Declaration
void IEventReceiver.Start()