From 6de70a9f41bd59fdc7314b0c73beb8f57f0a51f1 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Fri, 24 Jan 2020 13:52:17 +0000 Subject: [PATCH] Switch to using Mediatr --- .../CommandHandler/CommandRouterTests.cs | 62 ----------------- .../Commands/CommandTests.cs | 30 --------- .../TransactionRequestHandlerTests.cs} | 13 ++-- .../Requests/RequestTests.cs | 29 ++++++++ .../CommandHandlers/CommandRouter.cs | 64 ------------------ .../TransactionCommandHandler.cs | 67 ------------------- .../TransactionRequestHandler.cs | 54 +++++++++++++++ .../ProcessLogonTransactionRequest.cs} | 42 ++++++------ .../TransactionProcessor.BusinessLogic.csproj | 1 + TransactionProcessor.Testing/TestData.cs | 10 +-- .../Common/TransactionProcessorWebFactory.cs | 24 +++---- .../Controllers/TransactionController.cs | 30 +++++---- TransactionProcessor/Startup.cs | 16 ++++- 13 files changed, 157 insertions(+), 285 deletions(-) delete mode 100644 TransactionProcessor.BusinessLogic.Tests/CommandHandler/CommandRouterTests.cs delete mode 100644 TransactionProcessor.BusinessLogic.Tests/Commands/CommandTests.cs rename TransactionProcessor.BusinessLogic.Tests/{CommandHandler/TransactionCommandHandlerTests.cs => RequestHandler/TransactionRequestHandlerTests.cs} (61%) create mode 100644 TransactionProcessor.BusinessLogic.Tests/Requests/RequestTests.cs delete mode 100644 TransactionProcessor.BusinessLogic/CommandHandlers/CommandRouter.cs delete mode 100644 TransactionProcessor.BusinessLogic/CommandHandlers/TransactionCommandHandler.cs create mode 100644 TransactionProcessor.BusinessLogic/RequestHandlers/TransactionRequestHandler.cs rename TransactionProcessor.BusinessLogic/{Commands/ProcessLogonTransactionCommand.cs => Requests/ProcessLogonTransactionRequest.cs} (82%) diff --git a/TransactionProcessor.BusinessLogic.Tests/CommandHandler/CommandRouterTests.cs b/TransactionProcessor.BusinessLogic.Tests/CommandHandler/CommandRouterTests.cs deleted file mode 100644 index e48979fb..00000000 --- a/TransactionProcessor.BusinessLogic.Tests/CommandHandler/CommandRouterTests.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace TransactionProcessor.BusinessLogic.Tests.CommandHandler -{ - using System.Threading; - using System.Threading.Tasks; - using BusinessLogic.Commands; - using BusinessLogic.Services; - using CommandHandlers; - using Commands; - using Moq; - using Services; - using Shared.DomainDrivenDesign.CommandHandling; - using Shouldly; - using Testing; - using Xunit; - - public class CommandRouterTests - { - [Fact] - public void CommandRouter_ProcessLogonTransactionCommand_IsRouted() - { - Mock transactionDomainService = new Mock(); - ICommandRouter router = new CommandRouter(transactionDomainService.Object); - - ProcessLogonTransactionCommand command = TestData.ProcessLogonTransactionCommand; - - Should.NotThrow(async () => - { - await router.Route(command, CancellationToken.None); - }); - } - } - - public class TransactionDomainServiceTests - { - [Fact(Skip = "Complete once aggregate in place")] - public async Task TransactionDomainService_ProcessLogonTransaction_LogonTransactionIsProcesses() - { - //Mock> estateAggregateRepository = new Mock>(); - //estateAggregateRepository.Setup(m => m.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(new EstateAggregate()); - //estateAggregateRepository.Setup(m => m.SaveChanges(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask); - - //Mock aggregateRepositoryManager = new Mock(); - //aggregateRepositoryManager.Setup(x => x.GetAggregateRepository(It.IsAny())).Returns(estateAggregateRepository.Object); - - //EstateDomainService domainService = new EstateDomainService(aggregateRepositoryManager.Object); - - //Should.NotThrow(async () => - //{ - // await domainService.CreateEstate(TestData.EstateId, - // TestData.EstateName, - // CancellationToken.None); - //}); - throw new NotImplementedException(); - } - } -} - - diff --git a/TransactionProcessor.BusinessLogic.Tests/Commands/CommandTests.cs b/TransactionProcessor.BusinessLogic.Tests/Commands/CommandTests.cs deleted file mode 100644 index 6b94e5d8..00000000 --- a/TransactionProcessor.BusinessLogic.Tests/Commands/CommandTests.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace TransactionProcessor.BusinessLogic.Tests.Commands -{ - using BusinessLogic.Commands; - using Shouldly; - using Testing; - using Xunit; - - public class CommandTests - { - [Fact] - public void ProcessLogonTransactionCommand_CanBeCreated_IsCreated() - { - ProcessLogonTransactionCommand processLogonTransactionCommand = ProcessLogonTransactionCommand.Create(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.DeviceIdentifier,TestData.TransactionType, TestData.TransactionDateTime, - TestData.TransactionNumber); - - processLogonTransactionCommand.ShouldNotBeNull(); - processLogonTransactionCommand.CommandId.ShouldNotBe(Guid.Empty); - processLogonTransactionCommand.EstateId.ShouldBe(TestData.EstateId); - processLogonTransactionCommand.MerchantId.ShouldBe(TestData.MerchantId); - processLogonTransactionCommand.DeviceIdentifier.ShouldBe(TestData.DeviceIdentifier); - processLogonTransactionCommand.TransactionType.ShouldBe(TestData.TransactionType); - processLogonTransactionCommand.TransactionDateTime.ShouldBe(TestData.TransactionDateTime); - processLogonTransactionCommand.TransactionNumber.ShouldBe(TestData.TransactionNumber); - } - } -} diff --git a/TransactionProcessor.BusinessLogic.Tests/CommandHandler/TransactionCommandHandlerTests.cs b/TransactionProcessor.BusinessLogic.Tests/RequestHandler/TransactionRequestHandlerTests.cs similarity index 61% rename from TransactionProcessor.BusinessLogic.Tests/CommandHandler/TransactionCommandHandlerTests.cs rename to TransactionProcessor.BusinessLogic.Tests/RequestHandler/TransactionRequestHandlerTests.cs index 54cdb2b4..964b1c89 100644 --- a/TransactionProcessor.BusinessLogic.Tests/CommandHandler/TransactionCommandHandlerTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/RequestHandler/TransactionRequestHandlerTests.cs @@ -1,26 +1,27 @@ namespace TransactionProcessor.BusinessLogic.Tests.CommandHandler { using System.Threading; - using BusinessLogic.Commands; using BusinessLogic.Services; - using CommandHandlers; using Commands; + using MediatR; using Moq; + using RequestHandlers; + using Requests; using Services; using Shared.DomainDrivenDesign.CommandHandling; using Shouldly; using Testing; using Xunit; - public class TransactionCommandHandlerTests + public class TransactionRequestHandlerTests { [Fact] - public void EstateCommandHandler_CreateEstateCommand_IsHandled() + public void TransactionRequestHandler_ProcessLogonTransactionRequest_IsHandled() { Mock transactionDomainService = new Mock(); - ICommandHandler handler = new TransactionCommandHandler(transactionDomainService.Object); + TransactionRequestHandler handler = new TransactionRequestHandler(transactionDomainService.Object); - ProcessLogonTransactionCommand command = TestData.ProcessLogonTransactionCommand; + ProcessLogonTransactionRequest command = TestData.ProcessLogonTransactionRequest; Should.NotThrow(async () => { diff --git a/TransactionProcessor.BusinessLogic.Tests/Requests/RequestTests.cs b/TransactionProcessor.BusinessLogic.Tests/Requests/RequestTests.cs new file mode 100644 index 00000000..ee6c12bf --- /dev/null +++ b/TransactionProcessor.BusinessLogic.Tests/Requests/RequestTests.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TransactionProcessor.BusinessLogic.Tests.Commands +{ + using Requests; + using Shouldly; + using Testing; + using Xunit; + + public class RequestTests + { + [Fact] + public void ProcessLogonTransactionRequest_CanBeCreated_IsCreated() + { + ProcessLogonTransactionRequest processLogonTransactionRequest = ProcessLogonTransactionRequest.Create(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.DeviceIdentifier,TestData.TransactionType, TestData.TransactionDateTime, + TestData.TransactionNumber); + + processLogonTransactionRequest.ShouldNotBeNull(); + processLogonTransactionRequest.EstateId.ShouldBe(TestData.EstateId); + processLogonTransactionRequest.MerchantId.ShouldBe(TestData.MerchantId); + processLogonTransactionRequest.DeviceIdentifier.ShouldBe(TestData.DeviceIdentifier); + processLogonTransactionRequest.TransactionType.ShouldBe(TestData.TransactionType); + processLogonTransactionRequest.TransactionDateTime.ShouldBe(TestData.TransactionDateTime); + processLogonTransactionRequest.TransactionNumber.ShouldBe(TestData.TransactionNumber); + } + } +} diff --git a/TransactionProcessor.BusinessLogic/CommandHandlers/CommandRouter.cs b/TransactionProcessor.BusinessLogic/CommandHandlers/CommandRouter.cs deleted file mode 100644 index a33c7f4f..00000000 --- a/TransactionProcessor.BusinessLogic/CommandHandlers/CommandRouter.cs +++ /dev/null @@ -1,64 +0,0 @@ -namespace TransactionProcessor.BusinessLogic.CommandHandlers -{ - using System.Threading; - using System.Threading.Tasks; - using Commands; - using Services; - using Shared.DomainDrivenDesign.CommandHandling; - - /// - /// - /// - /// - public class CommandRouter : ICommandRouter - { - #region Fields - - /// - /// The transaction domain service - /// - private readonly ITransactionDomainService TransactionDomainService; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The transaction domain service. - public CommandRouter(ITransactionDomainService transactionDomainService) - { - this.TransactionDomainService = transactionDomainService; - } - - #endregion - - #region Methods - - /// - /// Routes the specified command. - /// - /// The command. - /// The cancellation token. - public async Task Route(ICommand command, - CancellationToken cancellationToken) - { - ICommandHandler commandHandler = CreateHandler((dynamic)command); - - await commandHandler.Handle(command, cancellationToken); - } - - /// - /// Creates the handler. - /// - /// The command. - /// - private ICommandHandler CreateHandler(ProcessLogonTransactionCommand command) - { - return new TransactionCommandHandler(this.TransactionDomainService); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic/CommandHandlers/TransactionCommandHandler.cs b/TransactionProcessor.BusinessLogic/CommandHandlers/TransactionCommandHandler.cs deleted file mode 100644 index 295f3ce5..00000000 --- a/TransactionProcessor.BusinessLogic/CommandHandlers/TransactionCommandHandler.cs +++ /dev/null @@ -1,67 +0,0 @@ -namespace TransactionProcessor.BusinessLogic.CommandHandlers -{ - using System.Threading; - using System.Threading.Tasks; - using Commands; - using Models; - using Services; - using Shared.DomainDrivenDesign.CommandHandling; - - /// - /// - /// - /// - public class TransactionCommandHandler : ICommandHandler - { - #region Fields - - /// - /// The transaction domain service - /// - private readonly ITransactionDomainService TransactionDomainService; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The transaction domain service. - public TransactionCommandHandler(ITransactionDomainService transactionDomainService) - { - this.TransactionDomainService = transactionDomainService; - } - - #endregion - - #region Methods - - /// - /// Handles the specified command. - /// - /// The command. - /// The cancellation token. - public async Task Handle(ICommand command, - CancellationToken cancellationToken) - { - await this.HandleCommand((dynamic)command, cancellationToken); - } - - /// - /// Handles the command. - /// - /// The command. - /// The cancellation token. - private async Task HandleCommand(ProcessLogonTransactionCommand command, - CancellationToken cancellationToken) - { - ProcessLogonTransactionResponse logonResponse = await this.TransactionDomainService.ProcessLogonTransaction(command.TransactionId, command.EstateId, - command.MerchantId, command.TransactionDateTime, command.TransactionNumber, command.DeviceIdentifier, cancellationToken); - - command.Response = logonResponse; - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic/RequestHandlers/TransactionRequestHandler.cs b/TransactionProcessor.BusinessLogic/RequestHandlers/TransactionRequestHandler.cs new file mode 100644 index 00000000..fbe26d73 --- /dev/null +++ b/TransactionProcessor.BusinessLogic/RequestHandlers/TransactionRequestHandler.cs @@ -0,0 +1,54 @@ +namespace TransactionProcessor.BusinessLogic.RequestHandlers +{ + using System.Threading; + using System.Threading.Tasks; + using MediatR; + using Models; + using Requests; + using Services; + + /// + /// + /// + /// + /// + public class TransactionRequestHandler : IRequestHandler + { + #region Fields + + /// + /// The transaction domain service + /// + private readonly ITransactionDomainService TransactionDomainService; + + #endregion + + #region Constructors + + public TransactionRequestHandler(ITransactionDomainService transactionDomainService) + { + this.TransactionDomainService = transactionDomainService; + } + + #endregion + + #region Methods + + public async Task Handle(ProcessLogonTransactionRequest request, + CancellationToken cancellationToken) + { + ProcessLogonTransactionResponse logonResponse = + await this.TransactionDomainService.ProcessLogonTransaction(request.TransactionId, + request.EstateId, + request.MerchantId, + request.TransactionDateTime, + request.TransactionNumber, + request.DeviceIdentifier, + cancellationToken); + + return logonResponse; + } + + #endregion + } +} \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic/Commands/ProcessLogonTransactionCommand.cs b/TransactionProcessor.BusinessLogic/Requests/ProcessLogonTransactionRequest.cs similarity index 82% rename from TransactionProcessor.BusinessLogic/Commands/ProcessLogonTransactionCommand.cs rename to TransactionProcessor.BusinessLogic/Requests/ProcessLogonTransactionRequest.cs index 43e9c585..06c998c7 100644 --- a/TransactionProcessor.BusinessLogic/Commands/ProcessLogonTransactionCommand.cs +++ b/TransactionProcessor.BusinessLogic/Requests/ProcessLogonTransactionRequest.cs @@ -1,21 +1,19 @@ -namespace TransactionProcessor.BusinessLogic.Commands +namespace TransactionProcessor.BusinessLogic.Requests { using System; + using MediatR; using Models; - using Shared.DomainDrivenDesign.CommandHandling; /// /// /// - /// - public class ProcessLogonTransactionCommand : Command + /// + public class ProcessLogonTransactionRequest : IRequest { - public Guid TransactionId { get; private set; } - #region Constructors /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The transaction identifier. /// The estate identifier. @@ -24,15 +22,13 @@ public class ProcessLogonTransactionCommand : CommandType of the transaction. /// The transaction date time. /// The transaction number. - /// The command identifier. - private ProcessLogonTransactionCommand(Guid transactionId, + private ProcessLogonTransactionRequest(Guid transactionId, Guid estateId, Guid merchantId, String deviceIdentifier, String transactionType, DateTime transactionDateTime, - String transactionNumber, - Guid commandId) : base(commandId) + String transactionNumber) { this.TransactionId = transactionId; this.EstateId = estateId; @@ -48,20 +44,20 @@ private ProcessLogonTransactionCommand(Guid transactionId, #region Properties /// - /// Gets the estate identifier. + /// Gets the device identifier. /// /// - /// The estate identifier. + /// The device identifier. /// - public Guid EstateId { get; } + public String DeviceIdentifier { get; } /// - /// Gets the device identifier. + /// Gets the estate identifier. /// /// - /// The device identifier. + /// The estate identifier. /// - public String DeviceIdentifier { get; } + public Guid EstateId { get; } /// /// Gets the merchant identifier. @@ -79,6 +75,14 @@ private ProcessLogonTransactionCommand(Guid transactionId, /// public DateTime TransactionDateTime { get; } + /// + /// Gets the transaction identifier. + /// + /// + /// The transaction identifier. + /// + public Guid TransactionId { get; } + /// /// Gets the transaction number. /// @@ -110,7 +114,7 @@ private ProcessLogonTransactionCommand(Guid transactionId, /// The transaction date time. /// The transaction number. /// - public static ProcessLogonTransactionCommand Create(Guid transactionId, + public static ProcessLogonTransactionRequest Create(Guid transactionId, Guid estateId, Guid merchantId, String deviceIdentifier, @@ -118,7 +122,7 @@ public static ProcessLogonTransactionCommand Create(Guid transactionId, DateTime transactionDateTime, String transactionNumber) { - return new ProcessLogonTransactionCommand(transactionId, estateId, merchantId, deviceIdentifier, transactionType, transactionDateTime, transactionNumber, Guid.NewGuid()); + return new ProcessLogonTransactionRequest(transactionId, estateId, merchantId, deviceIdentifier, transactionType, transactionDateTime, transactionNumber); } #endregion diff --git a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj index 71b01d13..75cfea3d 100644 --- a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj +++ b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj @@ -8,6 +8,7 @@ + diff --git a/TransactionProcessor.Testing/TestData.cs b/TransactionProcessor.Testing/TestData.cs index a8bc5737..5b2e14d0 100644 --- a/TransactionProcessor.Testing/TestData.cs +++ b/TransactionProcessor.Testing/TestData.cs @@ -4,7 +4,7 @@ namespace TransactionProcessor.Testing { - using BusinessLogic.Commands; + using BusinessLogic.Requests; using Models; using TransactionAggregate; @@ -24,10 +24,10 @@ public class TestData public static Guid MerchantId = Guid.Parse("833B5AAC-A5C5-46C2-A499-F2B4252B2942"); public static Guid TransactionId = Guid.Parse("AE89B2F6-307B-46F4-A8E7-CEF27097D766"); - public static ProcessLogonTransactionCommand ProcessLogonTransactionCommand = ProcessLogonTransactionCommand.Create( TestData.TransactionId, TestData.EstateId, TestData.MerchantId, - TestData.DeviceIdentifier, TestData.TransactionType, - TestData.TransactionDateTime, - TestData.TransactionNumber); + public static ProcessLogonTransactionRequest ProcessLogonTransactionRequest = ProcessLogonTransactionRequest.Create( TestData.TransactionId, TestData.EstateId, TestData.MerchantId, + TestData.DeviceIdentifier, TestData.TransactionType, + TestData.TransactionDateTime, + TestData.TransactionNumber); public static String DeviceIdentifier = "1234567890"; diff --git a/TransactionProcessor.Tests/Common/TransactionProcessorWebFactory.cs b/TransactionProcessor.Tests/Common/TransactionProcessorWebFactory.cs index 9f5d0206..2dedf03b 100644 --- a/TransactionProcessor.Tests/Common/TransactionProcessorWebFactory.cs +++ b/TransactionProcessor.Tests/Common/TransactionProcessorWebFactory.cs @@ -7,7 +7,7 @@ namespace TransactionProcessor.Tests.Common using System.Net.Http; using System.Threading; using System.Threading.Tasks; - using BusinessLogic.Commands; + using MediatR; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Authorization; using Microsoft.AspNetCore.Mvc.Testing; @@ -23,13 +23,13 @@ public class TransactionProcessorWebFactory : WebApplicationFactory commandRouterMock = this.CreateCommandRouterMock(); + Mock mediatorMock = this.CreateMediatorMock(); builder.ConfigureServices((builderContext, services) => { - if (commandRouterMock != null) + if (mediatorMock != null) { - services.AddSingleton(commandRouterMock.Object); + services.AddSingleton(mediatorMock.Object); } services.AddMvc(options => @@ -41,21 +41,13 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) ; } - private Mock CreateCommandRouterMock() + private Mock CreateMediatorMock() { - Mock commandRouterMock = new Mock(MockBehavior.Strict); + Mock mediatorMock = new Mock(MockBehavior.Strict); - commandRouterMock.Setup(c => c.Route(It.IsAny(), It.IsAny())).Returns((ProcessLogonTransactionCommand command, CancellationToken cancellationToken) => - { - command.Response = new ProcessLogonTransactionResponse - { - ResponseMessage = "SUCCESS", - ResponseCode = "0000" - }; - return Task.CompletedTask; - }); + mediatorMock.Setup(c => c.Send(It.IsAny>(), It.IsAny())).Returns(Task.FromResult("Hello")); - return commandRouterMock; + return mediatorMock; } } diff --git a/TransactionProcessor/Controllers/TransactionController.cs b/TransactionProcessor/Controllers/TransactionController.cs index 0cdfa703..82c113aa 100644 --- a/TransactionProcessor/Controllers/TransactionController.cs +++ b/TransactionProcessor/Controllers/TransactionController.cs @@ -4,12 +4,14 @@ using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; - using BusinessLogic.Commands; + using BusinessLogic.Requests; using Common; using DataTransferObjects; using Factories; + using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; + using Models; using Newtonsoft.Json; using Shared.DomainDrivenDesign.CommandHandling; @@ -27,9 +29,9 @@ public class TransactionController : ControllerBase #region Fields /// - /// The command router + /// The mediator /// - private readonly ICommandRouter CommandRouter; + private readonly IMediator Mediator; /// /// The model factory @@ -45,10 +47,10 @@ public class TransactionController : ControllerBase /// /// The command router. /// The model factory. - public TransactionController(ICommandRouter commandRouter, + public TransactionController(IMediator mediator, IModelFactory modelFactory) { - this.CommandRouter = commandRouter; + this.Mediator = mediator; this.ModelFactory = modelFactory; } @@ -101,17 +103,17 @@ private async Task ProcessSpecificMessage(LogonTransactionReq { Guid transactionId = Guid.NewGuid(); - ProcessLogonTransactionCommand command = ProcessLogonTransactionCommand.Create(transactionId, - logonTransactionRequest.EstateId, - logonTransactionRequest.MerchantId, - logonTransactionRequest.DeviceIdentifier, - logonTransactionRequest.TransactionType, - logonTransactionRequest.TransactionDateTime, - logonTransactionRequest.TransactionNumber); + ProcessLogonTransactionRequest request = ProcessLogonTransactionRequest.Create(transactionId, + logonTransactionRequest.EstateId, + logonTransactionRequest.MerchantId, + logonTransactionRequest.DeviceIdentifier, + logonTransactionRequest.TransactionType, + logonTransactionRequest.TransactionDateTime, + logonTransactionRequest.TransactionNumber); - await this.CommandRouter.Route(command, cancellationToken); + ProcessLogonTransactionResponse response = await this.Mediator.Send(request, cancellationToken); - return this.ModelFactory.ConvertFrom(command.Response); + return this.ModelFactory.ConvertFrom(response); } #endregion diff --git a/TransactionProcessor/Startup.cs b/TransactionProcessor/Startup.cs index 2db7a681..73d67bab 100644 --- a/TransactionProcessor/Startup.cs +++ b/TransactionProcessor/Startup.cs @@ -16,14 +16,17 @@ namespace TransactionProcessor using System.IO; using System.Reflection; using Autofac; - using BusinessLogic.CommandHandlers; + using BusinessLogic.RequestHandlers; + using BusinessLogic.Requests; using BusinessLogic.Services; using Common; using EventStore.ClientAPI; + using MediatR; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.Extensions.Options; + using Models; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using NLog.Extensions.Logging; @@ -61,7 +64,7 @@ public void ConfigureServices(IServiceCollection services) { this.ConfigureMiddlewareServices(services); - services.AddSingleton(); + services.AddTransient(); } public void ConfigureContainer(ContainerBuilder builder) @@ -112,6 +115,15 @@ public void ConfigureContainer(ContainerBuilder builder) builder.RegisterType>().As>().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); + + // request & notification handlers + builder.Register(context => + { + var c = context.Resolve(); + return t => c.Resolve(t); + }); + + builder.RegisterType().As>().SingleInstance(); } private void ConfigureMiddlewareServices(IServiceCollection services)