/// <summary> /// Processes the specified command. /// </summary> /// <param name="command"> /// The command to process. /// </param> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. Do not process <paramref name="command" /> using /// <paramref name="mediator" />, as doing so will generally result in infinite-looping. /// </param> /// <param name="controlToken"> /// A token that ensures thread safety for the operation. /// </param> protected sealed override void Process(TCommand command, ICommandMediator mediator, ConcurrencyControlToken controlToken) { if (Transaction.State == DataAccessTransactionState.Ready) { try { Transaction.Begin(); Process(command, Repositories, Transaction, controlToken); if (Transaction.State == DataAccessTransactionState.InProgress) { controlToken.AttachTask(Transaction.CommitAsync()); } return; } catch { if (Transaction.State == DataAccessTransactionState.InProgress) { controlToken.AttachTask(Transaction.RejectAsync()); } throw; } } throw new InvalidOperationException($"The transaction is in the invalid state, {Transaction.State}."); }
public StockItemController(ICommandMediator commandMediator, InventoryRepository repository, ILogger <StockItemController> logger) { _commandMediator = commandMediator; _queryMediator = repository; _logger = logger; }
public GenericCommandTests() { var container = new Container(); container.Configure(configure => { configure.AddRegistry(new TestRegistry()); }); this.mediator = container.GetInstance<ICommandMediator>(); this.emailSender = container.GetInstance<EmailSender>(); }
public CRUDCommandsTests() { var container = new Container(); container.Configure(configure => { configure.AddRegistry(new TestRegistry()); }); this.mediator = container.GetInstance <ICommandMediator>(); this.sampleAggregateRepository = container.GetInstance <IRepository <SampleAggregate> >(); }
/// <summary> /// Processes the specified command. /// </summary> /// <param name="command"> /// The command to process. /// </param> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. Do not process <paramref name="command" /> using /// <paramref name="mediator" />, as doing so will generally result in infinite-looping. /// </param> /// <param name="controlToken"> /// A token that ensures thread safety for the operation. /// </param> protected override void Process(HeartbeatMessage command, ICommandMediator mediator, ConcurrencyControlToken controlToken) { var pingRequest = new PingRequestMessage(); var pingResponse = (PingResponseMessage)null; var stopwatch = Stopwatch.StartNew(); pingResponse = mediator.Process <PingResponseMessage>(pingRequest); stopwatch.Stop(); if (pingResponse is null == false && pingResponse.RequestMessageIdentifier == pingRequest.Identifier) { Console.WriteLine($"Success! The round trip ping operation completed in {stopwatch.ElapsedMilliseconds} milliseconds."); return; } Console.WriteLine("The round trip ping operation failed."); }
public ProductController(ICommandMediator mediator) { this.mediator = mediator; }
/// <summary> /// Initializes a new instance of the <see cref="PrototypeCommandHandler{TCommand}" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <param name="repositoryFactory"> /// The factory that produces data access repositories for the handler. /// </param> /// <param name="isolationLevel"> /// The isolation level for the transaction, or <see cref="IsolationLevel.Unspecified" /> to use the database default. The /// default value is <see cref="IsolationLevel.Unspecified" />. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" /> -or- <paramref name="repositoryFactory" /> is /// <see langword="null" />. /// </exception> protected PrototypeCommandHandler(ICommandMediator mediator, PrototypeRepositoryFactory repositoryFactory, IsolationLevel isolationLevel) : base(mediator, repositoryFactory, isolationLevel) { return; }
/// <summary> /// Initializes a new instance of the <see cref="PrototypeCommandHandler{TCommand}" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <param name="repositoryFactory"> /// The factory that produces data access repositories for the handler. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" /> -or- <paramref name="repositoryFactory" /> is /// <see langword="null" />. /// </exception> protected PrototypeCommandHandler(ICommandMediator mediator, PrototypeRepositoryFactory repositoryFactory) : base(mediator, repositoryFactory) { return; }
/// <summary> /// Initializes a new instance of the <see cref="GetFibonacciNumberValuesCommandHandler" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <param name="repositoryFactory"> /// The factory that produces data access repositories for the handler. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" /> -or- <paramref name="repositoryFactory" /> is /// <see langword="null" />. /// </exception> public GetFibonacciNumberValuesCommandHandler(ICommandMediator mediator, PrototypeRepositoryFactory repositoryFactory) : base(mediator, repositoryFactory) { return; }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationController" /> class. /// </summary> /// <param name="applicationConfiguration"> /// Configuration information for the application. /// </param> /// <param name="mediator"> /// A processing intermediary for commands issued by the controller. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="applicationConfiguration" /> is <see langword="null" /> -or- <paramref name="mediator" /> is /// <see langword="null" />. /// </exception> protected ApplicationController(IConfiguration applicationConfiguration, ICommandMediator mediator) { ApplicationConfiguration = applicationConfiguration.RejectIf().IsNull(nameof(applicationConfiguration)).TargetArgument; Mediator = mediator.RejectIf().IsNull(nameof(mediator)).TargetArgument; }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationStoppingMessageSubscriber" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" />. /// </exception> public ApplicationStoppingMessageSubscriber(ICommandMediator mediator) : base(mediator) { return; }
/// <summary> /// Initializes a new instance of the <see cref="HomeController" /> class. /// </summary> /// <param name="applicationConfiguration"> /// Configuration information for the application. /// </param> /// <param name="mediator"> /// A processing intermediary for commands issued by the controller. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="applicationConfiguration" /> is <see langword="null" /> -or- <paramref name="mediator" /> is /// <see langword="null" />. /// </exception> public HomeController(IConfiguration applicationConfiguration, ICommandMediator mediator) : base(applicationConfiguration, mediator) { return; }
/// <summary> /// Processes the specified command. /// </summary> /// <param name="command"> /// The command to process. /// </param> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. Do not process <paramref name="command" /> using /// <paramref name="mediator" />, as doing so will generally result in infinite-looping. /// </param> /// <param name="controlToken"> /// A token that ensures thread safety for the operation. /// </param> /// <returns> /// The result that is emitted by processing the command. /// </returns> protected sealed override Guid Process(SimulatedCommandWithResult command, ICommandMediator mediator, ConcurrencyControlToken controlToken) { command.IsProcessed = true; return(command.Identifier); }
/// <summary> /// Initializes a new instance of the <see cref="HeartbeatMessageSubscriber" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" />. /// </exception> public HeartbeatMessageSubscriber(ICommandMediator mediator) : base(mediator) { return; }
public DisposedStockItemController(ICommandMediator commandMediator) { _commandMediator = commandMediator; }
/// <summary> /// Initializes a new instance of the <see cref="RequestSubscriber{TRequestMessage, TResponseMessage}" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" />. /// </exception> protected RequestSubscriber(ICommandMediator mediator) : base(mediator) { return; }
public AttributeController(ICommandMediator mediator) { this.mediator = mediator; }
/// <summary> /// Initializes a new instance of the <see cref="TopicSubscriber{TMessage}" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" />. /// </exception> protected TopicSubscriber(ICommandMediator mediator) : base(mediator, MessagingEntityType.Topic) { return; }
public CategoryController(ICommandMediator mediator) { this.mediator = mediator; }
/// <summary> /// Initializes a new instance of the <see cref="QueueSubscriber{TMessage}" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" />. /// </exception> protected QueueSubscriber(ICommandMediator mediator) : base(mediator, MessagingEntityType.Queue) { return; }
/// <summary> /// Initializes a new instance of the <see cref="DataAccessCommandHandler{TCommand}" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <param name="repositoryFactory"> /// The factory that produces data access repositories for the handler. /// </param> /// <param name="transaction"> /// A transaction that is used to process the command. /// </param> /// <exception cref="ArgumentException"> /// <paramref name="transaction" /> is in an invalid state. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" /> -or- <paramref name="repositoryFactory" /> is /// <see langword="null" /> -or- <paramref name="transaction" /> is <see langword="null" />. /// </exception> protected DataAccessCommandHandler(ICommandMediator mediator, IDataAccessRepositoryFactory repositoryFactory, IDataAccessTransaction transaction) : base(mediator) { Repositories = new FactoryProducedInstanceGroup(repositoryFactory); Transaction = transaction.RejectIf().IsNull(nameof(transaction)).OrIf((argument) => argument.State != DataAccessTransactionState.Ready, nameof(transaction)).TargetArgument; }
/// <summary> /// Initializes a new instance of the <see cref="CommandHandler{TCommand}" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" />. /// </exception> protected CommandHandler(ICommandMediator mediator) : base() { Mediator = mediator.RejectIf().IsNull(nameof(mediator)).TargetArgument; }
/// <summary> /// Initializes a new instance of the <see cref="SimulatedCommandWithResultHandler" /> class. /// </summary> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" />. /// </exception> public SimulatedCommandWithResultHandler(ICommandMediator mediator) : base(mediator) { return; }
/// <summary> /// Processes the specified command. /// </summary> /// <param name="command"> /// The command to process. /// </param> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. Do not process <paramref name="command" /> using /// <paramref name="mediator" />, as doing so will generally result in infinite-looping. /// </param> /// <param name="controlToken"> /// A token that ensures thread safety for the operation. /// </param> protected abstract void Process(TCommand command, ICommandMediator mediator, ConcurrencyControlToken controlToken);
/// <summary> /// Initializes a new instance of the <see cref="MessageHandler{TMessage}" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <param name="role"> /// The role of the handler. /// </param> /// <param name="entityType"> /// The targeted entity type. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="role" /> is equal to <see cref="MessageHandlerRole.Unspecified" /> -or- <paramref name="entityType" /> is /// equal to <see cref="MessagingEntityType.Unspecified" />. /// </exception> protected MessageHandler(ICommandMediator mediator, MessageHandlerRole role, MessagingEntityType entityType) : base(mediator) { EntityType = entityType.RejectIf().IsEqualToValue(MessagingEntityType.Unspecified, nameof(entityType)); Role = role.RejectIf().IsEqualToValue(MessageHandlerRole.Unspecified, nameof(role)); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionRaisedMessageSubscriber" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" />. /// </exception> public ExceptionRaisedMessageSubscriber(ICommandMediator mediator) : base(mediator) { return; }
public ExecuteCommandEventArgs(ICommandMediator mediator) { this.mediator = mediator; }
/// <summary> /// Initializes a new instance of the <see cref="MessagePublisher{TMessage}" /> class. /// </summary> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. /// </param> /// <param name="client"> /// A client that facilitates message publishing operations. /// </param> /// <param name="entityType"> /// The targeted entity type. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mediator" /> is <see langword="null" /> -or- <paramref name="client" /> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="entityType" /> is equal to <see cref="MessagingEntityType.Unspecified" />. /// </exception> protected MessagePublisher(ICommandMediator mediator, IMessagePublishingClient client, MessagingEntityType entityType) : base(mediator, MessageHandlerRole.Publisher, entityType) { Client = client.RejectIf().IsNull(nameof(client)).TargetArgument; }
/// <summary> /// Processes the specified command. /// </summary> /// <param name="command"> /// The command to process. /// </param> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. Do not process <paramref name="command" /> using /// <paramref name="mediator" />, as doing so will generally result in infinite-looping. /// </param> /// <param name="controlToken"> /// A token that ensures thread safety for the operation. /// </param> protected override void Process(ApplicationStoppingMessage command, ICommandMediator mediator, ConcurrencyControlToken controlToken) => Console.WriteLine($"{command.ApplicationEvent.Summary}{Environment.NewLine}");
/// <summary> /// Processes the specified command. /// </summary> /// <param name="command"> /// The command to process. /// </param> /// <param name="mediator"> /// A processing intermediary that is used to process sub-commands. Do not process <paramref name="command" /> using /// <paramref name="mediator" />, as doing so will generally result in infinite-looping. /// </param> /// <param name="controlToken"> /// A token that ensures thread safety for the operation. /// </param> protected override void Process(TMessage command, ICommandMediator mediator, ConcurrencyControlToken controlToken) => controlToken.AttachTask(Client.PublishAsync(command, EntityType));