예제 #1
0
파일: Program.cs 프로젝트: WSSFuryslav/CQRS
        public async Task Run()
        {
            //в веб-приложении вызов ConfigureServices происходит внутри ASP.Net
            //с аргументом IServiceCollection
            ConfigureServices(new ServiceCollection());

            using (var scope = CompositionRoot.BeginLifetimeScope())
            {
                var mediator          = scope.Resolve <IMediator>();
                var productController = new ProductController(mediator);
                var productDto1       = await productController.Register(new RegisterProductRequest()
                {
                    Name = "Apple",
                    Cost = 150d
                });

                Console.WriteLine($"{productDto1.Name}, {productDto1.Cost}");

                var productDto2 = await productController.Register(new RegisterProductRequest()
                {
                    Name = "Apple",
                    Cost = 170d
                });

                Console.WriteLine($"{productDto2.Name}, {productDto2.Cost}");
            }
        }
예제 #2
0
 public static async Task Execute(ICommand command)
 {
     using (var scope = CompositionRoot.BeginLifetimeScope())
     {
         var mediator = scope.Resolve <IMediator>();
         await mediator.Send(command);
     }
 }
예제 #3
0
 public static async Task <TResult> Execute <TResult>(ICommand <TResult> command)
 {
     using (var scope = CompositionRoot.BeginLifetimeScope())
     {
         var mediator = scope.Resolve <IMediator>();
         return(await mediator.Send(command));
     }
 }
        public static async Task <TResult> Execute <TResult>(IQuery <TResult> query)
        {
            using (ILifetimeScope scope = CompositionRoot.BeginLifetimeScope())
            {
                IMediator mediator = scope.Resolve <IMediator>();

                return(await mediator.Send(query));
            }
        }
예제 #5
0
        internal static async Task <TUseCaseOutput> Execute <TUseCaseOutput>(IUseCaseInput <TUseCaseOutput> useCase)
            where TUseCaseOutput : IUseCaseOutput
        {
            using (var scope = CompositionRoot.BeginLifetimeScope())
            {
                var _mediator = scope.Resolve <IMediator>();

                return(await _mediator.Send(useCase));
            }
        }
예제 #6
0
        public static void SeedDataForTest(Action <IncidentReportWriteDbContext> seed)
        {
            using (var scope = CompositionRoot.BeginLifetimeScope())
            {
                var dbContext = scope.Resolve <IncidentReportWriteDbContext>();

                dbContext.Database.EnsureCreated();
                seed?.Invoke(dbContext);

                dbContext.SaveChanges();
            }
        }
예제 #7
0
        public static async Task Execute(ICommand command)
        {
            // need to resolve the IMediator
            // from container, then
            // use the mediator to send the commands
            // the commands (ask a classes) are managed by an handler
            //

            // that means we need to inject into service project all dependencies we need
            using (var scope = CompositionRoot.BeginLifetimeScope())
            {
                var mediator = scope.Resolve <IMediator>();
                await mediator.Send(command);
            }
        }
예제 #8
0
 public static T Resolve <T>() where T : class
 {
     return(CompositionRoot.BeginLifetimeScope().Resolve <T>());
 }
예제 #9
0
 public async Task Handle(T @event)
 {
     using var scope = CompositionRoot.BeginLifetimeScope();
     //kbytner 02.02.2021 - Save Event To Process Later
 }
예제 #10
0
 private static void SubscribeToIntegrationEvents(ILogger logger)
 {
     var eventBus = CompositionRoot.BeginLifetimeScope().Resolve <IEventsBus>();
 }