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}"); } }
public static async Task Execute(ICommand command) { using (var scope = CompositionRoot.BeginLifetimeScope()) { var mediator = scope.Resolve <IMediator>(); await mediator.Send(command); } }
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)); } }
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)); } }
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(); } }
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); } }
public static T Resolve <T>() where T : class { return(CompositionRoot.BeginLifetimeScope().Resolve <T>()); }
public async Task Handle(T @event) { using var scope = CompositionRoot.BeginLifetimeScope(); //kbytner 02.02.2021 - Save Event To Process Later }
private static void SubscribeToIntegrationEvents(ILogger logger) { var eventBus = CompositionRoot.BeginLifetimeScope().Resolve <IEventsBus>(); }