/// <inheritdoc /> public async Task <TAggregateRoot> GetAsync <TAggregateRoot, TAggregateState>( string aggregateId, AggregateExecutionContext context) where TAggregateRoot : AggregateRoot <TAggregateState> where TAggregateState : AggregateState, new() { var aggregateRoot = CreateEmptyAggregate <TAggregateRoot, TAggregateState>(aggregateId, context); await FillAggregateHistoryAsync(aggregateRoot); return(aggregateRoot); }
/// <summary> /// Initializes a new instance of the <see cref="BaseAggregateRoot{TState}"/> class. /// </summary> /// <param name="id">Aggregate id.</param> /// <param name="context">Aggregate execution context.</param> protected BaseAggregateRoot(string id, AggregateExecutionContext context) : base(id) { Context = context; }
private static TAggregateRoot CreateEmptyAggregate <TAggregateRoot, TAggregateState>(string aggregateId, AggregateExecutionContext context) where TAggregateRoot : AggregateRoot <TAggregateState> where TAggregateState : AggregateState, new() { var type = typeof(TAggregateRoot); var constructorInfo = type.GetConstructor(new[] { typeof(string), typeof(AggregateExecutionContext) }) ?? throw new ArgumentNullException($"No contrsuctor with '{typeof(string)}, {typeof(AggregateExecutionContext)}' " + $"arguments is found in '{typeof(TAggregateRoot)}'."); var aggregateRoot = (TAggregateRoot)constructorInfo.Invoke(new object[] { aggregateId, context }); return(aggregateRoot); }
/// <inheritdoc /> public TAggregateRoot Create <TAggregateRoot, TAggregateState>(string aggregateId, AggregateExecutionContext context) where TAggregateRoot : AggregateRoot <TAggregateState> where TAggregateState : AggregateState, new() { return(CreateEmptyAggregate <TAggregateRoot, TAggregateState>(aggregateId, context)); }