コード例 #1
0
        /// <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}.");
        }
コード例 #2
0
ファイル: StockItemController.cs プロジェクト: lulzzz/GoFish
 public StockItemController(ICommandMediator commandMediator,
                            InventoryRepository repository,
                            ILogger <StockItemController> logger)
 {
     _commandMediator = commandMediator;
     _queryMediator   = repository;
     _logger          = logger;
 }
コード例 #3
0
        public GenericCommandTests()
        {
            var container = new Container();
            container.Configure(configure =>
            {
                configure.AddRegistry(new TestRegistry());
            });

            this.mediator = container.GetInstance<ICommandMediator>();
            this.emailSender = container.GetInstance<EmailSender>();
        }
コード例 #4
0
        public CRUDCommandsTests()
        {
            var container = new Container();

            container.Configure(configure =>
            {
                configure.AddRegistry(new TestRegistry());
            });

            this.mediator = container.GetInstance <ICommandMediator>();
            this.sampleAggregateRepository = container.GetInstance <IRepository <SampleAggregate> >();
        }
コード例 #5
0
        /// <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.");
        }
コード例 #6
0
 public ProductController(ICommandMediator mediator)
 {
     this.mediator = mediator;
 }
コード例 #7
0
 /// <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;
 }
コード例 #8
0
 /// <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;
 }
コード例 #10
0
 /// <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;
 }
コード例 #11
0
 /// <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;
 }
コード例 #12
0
 /// <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;
 }
コード例 #13
0
 /// <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);
 }
コード例 #14
0
 /// <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;
 }
コード例 #15
0
 public DisposedStockItemController(ICommandMediator commandMediator)
 {
     _commandMediator = commandMediator;
 }
コード例 #16
0
 /// <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;
 }
コード例 #17
0
 public AttributeController(ICommandMediator mediator)
 {
     this.mediator = mediator;
 }
コード例 #18
0
 /// <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;
 }
コード例 #19
0
 public CategoryController(ICommandMediator mediator)
 {
     this.mediator = mediator;
 }
コード例 #20
0
 /// <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;
 }
コード例 #21
0
 /// <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;
 }
コード例 #22
0
 /// <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;
 }
コード例 #23
0
 /// <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;
 }
コード例 #24
0
 /// <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);
コード例 #25
0
 /// <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));
 }
コード例 #26
0
 /// <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;
 }
コード例 #27
0
 public ExecuteCommandEventArgs(ICommandMediator mediator)
 {
     this.mediator = mediator;
 }
コード例 #28
0
 /// <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;
 }
コード例 #29
0
 /// <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}");
コード例 #30
0
 /// <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));