Пример #1
0
        protected async Task <CustomerAggregate> Prepare(
            IEventStore store,
            IAggregateRootServices services,
            ICollection <Action <CustomerAggregate> > useCaseActions)
        {
            Expect.NotNull(store, nameof(store));
            Expect.NotNull(services, nameof(services));
            Expect.NotEmpty(useCaseActions, nameof(useCaseActions));

            var streamId = Guid.NewGuid().ToString("N");
            var r        = new CustomerAggregate(streamId, services);

            using (var sess = store.OpenSession(suppressAmbientTransaction: true))
            {
                foreach (var action in useCaseActions)
                {
                    action(r);
                    var ok = await sess.SaveUncommitedEventsAsync <CustomerAggregate, Customer>(r).ConfigureAwait(false);

                    if (!ok)
                    {
                        throw new Exception("failed to prepare root aggregate");
                    }
                }
            }

            return(r);
        }
Пример #2
0
        public static void InitCurrent(IAggregateRootServices instance)
        {
            Expect.NotNull(instance, nameof(instance));
            if (current != null)
            {
                Trace.TraceWarning("AggregateRootServices.Current is already set");
            }

            current = instance;
        }
Пример #3
0
        protected AggregateRoot(string streamId, IAggregateRootServices services)
        {
            Expect.NotEmpty(streamId, nameof(streamId));
            Expect.NotNull(services, nameof(services));

            StreamId         = streamId;
            Data             = new T();
            uncommitedEvents = new List <object>();
            this.services    = services;
        }
Пример #4
0
        public static async Task <(CustomerAggregate root, bool ok)> LoadAsync(
            this IEventStoreSession sess,
            string streamId,
            IAggregateRootServices services)
        {
            var aggregate = new CustomerAggregate(streamId, services);
            var success   = await sess.HydrateAsync <CustomerAggregate, Customer>(aggregate).ConfigureAwait(false);

            return(success ? (aggregate, true) : (null, false));
        }
Пример #5
0
        public static CustomerAggregate AsDirtyCustomerAggregate(
            this ICollection <Action <CustomerAggregate> > useCase,
            IAggregateRootServices services,
            string streamId = null)
        {
            var id = streamId ?? Guid.NewGuid().ToString("N");
            var r  = new CustomerAggregate(id, services);

            foreach (var action in useCase)
            {
                action(r);
            }

            return(r);
        }
Пример #6
0
 public CustomerAggregate(IAggregateRootServices services)
     : this(Guid.NewGuid().ToString("N"), services)
 {
 }
Пример #7
0
 public CustomerAggregate(string streamId, IAggregateRootServices services)
     : base(streamId, services)
 {
 }