public Task <IEventStream> GetEventStreamAsync <TAggregateRoot>(AggregateRootIdentity identity) where TAggregateRoot : class, IAggregateRoot { Contract.Requires(identity != null); Contract.Ensures(Contract.Result <Task <IEventStream> >() != null); throw new NotImplementedException(); }
public Task <TAggregateRoot> GetByIdentityAsync(AggregateRootIdentity identity) { Contract.Requires(identity != null); Contract.Ensures(Contract.Result <Task <TAggregateRoot> >() != null); throw new NotImplementedException(); }
public TAggregateRoot Build(AggregateRootIdentity identity, TAggregateRootState state) { Contract.Requires(identity != null); Contract.Requires(state != null); Contract.Ensures(Contract.Result <TAggregateRoot>() != null); throw new NotImplementedException(); }
public AggregateRootCommandHandlingResult(Guid commandId, AggregateRootIdentity aggregateRootIdentity) : base(commandId) { Contract.Requires(commandId != Guid.Empty); Contract.Requires(aggregateRootIdentity != null); AggregateRootIdentity = aggregateRootIdentity; }
protected virtual Task <TAggregateRoot> GetAggregateRootAsync(AggregateRootIdentity identity) { Contract.Requires(identity != null); Contract.Ensures(Contract.Result <Task <TAggregateRoot> >() != null); // get aggregate root return(_repository.GetByIdentityAsync(identity)); }
public EventStoreCommandHandlingResult(Guid commandId, AggregateRootIdentity aggregateRootIdentity, TransactionIdentity transactionIdentity) : base(commandId, aggregateRootIdentity) { Contract.Requires(commandId != Guid.Empty); Contract.Requires(aggregateRootIdentity != null); Contract.Requires(transactionIdentity != null); TransactionIdentity = transactionIdentity; }
protected override TAggregateRoot GetAggregateRoot(AggregateRootIdentity identity) { // retrieve from cache or get from base handler and store in cache var aggregateRoot = _cache.AddOrGetExisting(GetCacheKey(identity), new Lazy <TAggregateRoot>(() => base.GetAggregateRoot(identity))); Contract.Assume(aggregateRoot != null); return(aggregateRoot); }
protected override async Task <TAggregateRoot> GetAggregateRootAsync(AggregateRootIdentity identity) { // retrieve from cache or get from base handler and store in cache var task = _cache.AddOrGetExisting(GetCacheKey(identity), new Lazy <Task <TAggregateRoot> >(() => base.GetAggregateRootAsync(identity))); Contract.Assume(task != null); return(await task); }
private static string GetCacheKey(AggregateRootIdentity identity) { Contract.Requires(identity != null); Contract.Ensures(string.IsNullOrWhiteSpace(Contract.Result <string>()) == false); var cacheKey = $"{typeof(TAggregateRoot).FullName}::{identity.Value}"; Contract.Assume(string.IsNullOrWhiteSpace(cacheKey) == false); return(cacheKey); }
public EventProvider(EventProviderIdentity identity, AggregateRootType type, AggregateRootIdentity aggregateRootIdentity) { Contract.Requires(type != null); Contract.Requires(aggregateRootIdentity != null); Contract.Requires(identity != null); Identity = identity; AggregateRootType = type; AggregateRootIdentity = aggregateRootIdentity; }
public static DomainEventCollection Create(Create command) { var identity = new AggregateRootIdentity(command.AggregateRootId); var domainEvent = new Created(Guid.NewGuid(), identity, command.BeginningBalance); var state = new AccountState(domainEvent); var aggregateRoot = new AccountAggregateRoot(identity, state); return(new DomainEventCollection(aggregateRoot, domainEvent)); }
private SqlCommand CreateSqlCommand(AggregateRootType aggregateRootType, AggregateRootIdentity identity) { var sqlCommand = new SqlCommand("[dbo].[GetDomainEvents]"); sqlCommand.CommandType = CommandType.StoredProcedure; // set parameters sqlCommand.Parameters.Add("@aggregateRootId", SqlDbType.UniqueIdentifier).Value = identity.Value; sqlCommand.Parameters.Add("@aggregateRootTypeId", SqlDbType.Binary, 16).Value = _typeFactory.GetHash(aggregateRootType.Type); return(sqlCommand); }
public TAggregateRoot GetByIdentity(AggregateRootIdentity identity) { Contract.Assume(identity != null); var eventStream = _eventStore.GetEventStream <TAggregateRoot>(identity); // build aggregate root from event stream var aggregateRoot = _eventStreamProcessor.Process(eventStream); // set external state tracker aggregateRoot.State.ExternalStateTracker = new EventProviderStateTracker(eventStream.EventProvider, eventStream.LatestVersion, _guidGenerator); return(aggregateRoot); }
public GetDomainEventsCommand(SqlSerializer serializer, ITypeFactory typeFactory, AggregateRootType aggregateRootType, AggregateRootIdentity aggregateRootIdentity) { Contract.Requires(serializer != null); Contract.Requires(aggregateRootType != null); Contract.Requires(typeFactory != null); Contract.Requires(aggregateRootIdentity != null); _serializer = serializer; _typeFactory = typeFactory; _aggregateRootType = aggregateRootType; _aggregateRootIdentity = aggregateRootIdentity; _command = CreateSqlCommand(aggregateRootType, aggregateRootIdentity); }
public IEventStream GetEventStream <TAggregateRoot>(AggregateRootIdentity identity) where TAggregateRoot : class, IAggregateRoot { try { // create new event provider type var eventProviderType = new AggregateRootType(typeof(TAggregateRoot)); // get event stream var eventStream = GetEventStream(eventProviderType, identity); Contract.Assume(eventStream != null); // return event stream return(eventStream); } catch (Exception ex) { throw new EventStoreException(ErrorGettingEventStream, ex); } }
protected abstract Task <EventStream> GetEventStreamAsync(AggregateRootType eventProviderType, AggregateRootIdentity aggregateRootIdentity);
protected override async Task <EventStream> GetEventStreamAsync(AggregateRootType eventProviderType, AggregateRootIdentity identity) { // establish command var command = new GetDomainEventsCommand(_serializer, _typeFactory, eventProviderType, identity); // create connection using (var conn = new SqlConnection(_connectionString)) { // connection needs to be open before executing await conn.OpenAsync(); // execute return(await command.ExecuteAsync(conn)); } }
protected async Task <ICommandHandlingResult> HandleAsync(ICommandHandlerContext <TCommand> context, AggregateRootIdentity identity) { Contract.Requires(context != null); Contract.Requires(identity != null); Contract.Ensures(Contract.Result <Task>() != null); // use identity to get aggregate root TAggregateRoot aggregateRoot = await GetAggregateRootAsync(identity); // execute command aggregateRoot.Execute(context.Command); // commit changes return(await _repository.CommitAsync(context, aggregateRoot)); }
protected ICommandHandlingResult Handle(ICommandHandlerContext <TCommand> context, AggregateRootIdentity identity) { Contract.Requires(context != null); Contract.Requires(identity != null); Contract.Ensures(Contract.Result <ICommandHandlingResult>() != null); // use identity to get aggregate root TAggregateRoot aggregateRoot = GetAggregateRoot(identity); // execute command aggregateRoot.Execute(context.Command); // commit changes return(_repository.Commit(context, aggregateRoot)); }
protected abstract EventStream GetEventStream(AggregateRootType eventProviderType, AggregateRootIdentity aggregateRootIdentity);
private AccountAggregateRoot(AggregateRootIdentity identity, AccountState state) : base(identity, state) { Contract.Requires(identity != null); Contract.Requires(state != null); }