示例#1
0
        public static Task Execute <T, TRepository>(this AggregateRootCommandExecutor <T, TRepository> executor, Envelope envelope, Func <IKey, T> handler)
            where T : AggregateRoot
            where TRepository : IRepository <T, IKey>
        {
            return(executor.Execute(() =>
            {
                IKey userKey;
                if (!envelope.Metadata.TryGet("UserKey", out userKey))
                {
                    if (envelope.Metadata.TryGet("UserId", out string userId))
                    {
                        userKey = StringKey.Create(userId, "User");
                    }
                    else
                    {
                        userKey = StringKey.Empty("User");
                    }
                }

                T model = handler(userKey);

                foreach (IEvent item in model.Events)
                {
                    if (item is UserEvent payload)
                    {
                        payload.UserKey = userKey;
                    }
                }

                return model;
            }));
        }
示例#2
0
 public static Task Execute <T, TRepository>(this AggregateRootCommandExecutor <T, TRepository> executor, Envelope envelope, Func <T> handler)
     where T : AggregateRoot
     where TRepository : IRepository <T, IKey>
 {
     return(Execute(executor, envelope, userKey => handler()));
 }
示例#3
0
 public static Task Execute <T, TRepository>(this AggregateRootCommandExecutor <T, TRepository> executor, IKey aggregateKey, Envelope envelope, Action <T> handler)
     where T : AggregateRoot
     where TRepository : IRepository <T, IKey>
 {
     return(Execute(executor, aggregateKey, envelope, (model, userKey) => handler(model)));
 }