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); }
public static void InitCurrent(IAggregateRootServices instance) { Expect.NotNull(instance, nameof(instance)); if (current != null) { Trace.TraceWarning("AggregateRootServices.Current is already set"); } current = instance; }
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; }
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)); }
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); }
public CustomerAggregate(IAggregateRootServices services) : this(Guid.NewGuid().ToString("N"), services) { }
public CustomerAggregate(string streamId, IAggregateRootServices services) : base(streamId, services) { }