Ejemplo n.º 1
0
        public async Task <bool> Handle(T @event)
        {
            try
            {
                using (var scope = MatchesCompositionRoot.BeginLifetimeScope())
                {
                    using (var connection = scope.Resolve <ISqlConnectionFactory>().GetOpenConnection())
                    {
                        string type = @event.GetType().FullName;
                        var    data = JsonConvert.SerializeObject(@event, new JsonSerializerSettings
                        {
                            ContractResolver = new AllPropertiesContractResolver()
                        });

                        var sql = "INSERT INTO [Match].[InboxMessages] (Id, OccurredOn, Type, Data) " +
                                  "VALUES (@Id, @OccurredOn, @Type, @Data)";

                        await connection.ExecuteScalarAsync(sql, new
                        {
                            @event.Id,
                            @event.OccurredOn,
                            type,
                            data
                        });

                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                throw new ApplicationException($"Unable to process message {@event}. Exception : {e.Message}");
            }
        }
Ejemplo n.º 2
0
 internal static async Task Execute(ICommand command)
 {
     using (var scope = MatchesCompositionRoot.BeginLifetimeScope())
     {
         var mediator = scope.Resolve <IMediator>();
         await mediator.Send(command);
     }
 }
Ejemplo n.º 3
0
 internal static async Task <TResult> Execute <TResult>(ICommand <TResult> command)
 {
     using (var scope = MatchesCompositionRoot.BeginLifetimeScope())
     {
         var mediator = scope.Resolve <IMediator>();
         return(await mediator.Send(command));
     }
 }
Ejemplo n.º 4
0
        private void InitializeDbContext()
        {
            var context        = MatchesCompositionRoot.BeginLifetimeScope().Resolve <MatchContext>();
            var teamRepository = MatchesCompositionRoot.BeginLifetimeScope().Resolve <ITeamRepository>();

            context.Database.Migrate();
            MatchContextInitializer.Initialize(context, teamRepository);
        }
Ejemplo n.º 5
0
        public static async Task <TResult> Execute <TResult>(IQuery <TResult> query)
        {
            using (var scope = MatchesCompositionRoot.BeginLifetimeScope())
            {
                var mediator = scope.Resolve <IMediator>();

                return(await mediator.Send(query));
            }
        }
Ejemplo n.º 6
0
        private static void SubscribeToIntegrationEvents(ILogger logger)
        {
            var eventBus = MatchesCompositionRoot.BeginLifetimeScope().Resolve <IEventsBus>();

            SubscribeToIntegrationEvent <NewUserRegisteredIntegrationEvent>(eventBus, logger);
        }