Esempio n. 1
0
        public async Task <TResult> ExecuteQueryAsync <TResult>(IQuery <TResult> query)
        {
            using var scope = BetCompositionRoot.BeginScope();
            var mediator = scope.ServiceProvider.GetService(typeof(IMediator)) as IMediator;

            return(await mediator.Send(query));
        }
Esempio n. 2
0
        private static void Initialize(IConfiguration configuration, IHttpContextAccessor httpContextAccessor, ILogger logger)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton(x => configuration.GetSection("AzureStorage").Get <AzureStorageConfiguration>());
            serviceCollection.AddDbContext <DbContext, BetFriendContext>(options => options.UseSqlServer(configuration.GetConnectionString("BetFriendDbContext")));
            serviceCollection.AddScoped(x => httpContextAccessor);
            serviceCollection.AddScoped <IMemberRepository, MemberRepository>();
            serviceCollection.AddScoped <IQueryMemberRepository, MemberQueryRepository>();
            serviceCollection.AddTransient <IDateTimeProvider, DateTimeProvider>();
            serviceCollection.AddScoped(x =>
            {
                var mongoClient = new MongoClient(configuration.GetConnectionString("MongoServerUrl"));
                return(mongoClient.GetDatabase(configuration["MongoDatabaseName"]));
            });
            serviceCollection.AddLogging(x => x.AddSerilog(logger));
            serviceCollection.AddScoped <IAuthenticationGateway, AuthenticationGateway>();
            serviceCollection.AddScoped <IBetRepository, BetRepository>();
            serviceCollection.AddScoped <IBetQueryRepository, BetQueryRepository>();
            serviceCollection.AddScoped <IFeedRepository, FeedRepository>();
            serviceCollection.AddScoped <IDomainEventsDispatcher, DomainEventsDispatcher>();
            serviceCollection.AddScoped <IDomainEventsAccessor, DomainEventsAccessor>();
            serviceCollection.AddScoped <IStorageDomainEventsRepository, AzureStorageDomainEventsRepository>();
            serviceCollection.AddScoped <IUnitOfWork, UnitOfWork>();
            serviceCollection.AddTransient(typeof(IPipelineBehavior <,>), typeof(LoggingBehavior <,>));
            serviceCollection.AddTransient(typeof(IPipelineBehavior <,>), typeof(UnitOfWorkBehavior <,>));
            serviceCollection.AddMediatR(typeof(LaunchBetCommand).Assembly);
            BetCompositionRoot.SetProvider(serviceCollection.BuildServiceProvider());
        }
Esempio n. 3
0
 public async Task ExecuteNotificationAsync(INotificationCommand notification)
 {
     using var scope = BetCompositionRoot.BeginScope();
     var mediator = scope.ServiceProvider.GetService(typeof(IMediator)) as IMediator;
     await mediator.Publish(notification);
 }
Esempio n. 4
0
 public async Task ExecuteCommandAsync <TRequest>(ICommand <TRequest> command)
 {
     using var scope = BetCompositionRoot.BeginScope();
     var mediator = scope.ServiceProvider.GetService(typeof(IMediator)) as IMediator;
     await mediator.Send(command);
 }