Interface FlexAggregateRepository<ID,AGGREGATE_TYPE extends FlexAggregate<ID,AGGREGATE_TYPE>>

Type Parameters:
ID - the aggregate id type
AGGREGATE_TYPE - the aggregate type
All Known Implementing Classes:
FlexAggregateRepository.DefaultFlexAggregateRepository

public interface FlexAggregateRepository<ID,AGGREGATE_TYPE extends FlexAggregate<ID,AGGREGATE_TYPE>>
Opinionated FlexAggregate Repository that's built to persist and load a specific FlexAggregate type in combination with EventStore, EventStoreUnitOfWorkFactory and a FlexAggregateRepository.

Here's how to create an FlexAggregateRepository instance that can persist an FlexAggregate of type Order which has an aggregate id of type OrderId:


 FlexAggregateRepository<OrderId, Order> repository =
      FlexAggregateRepository.from(
                eventStores,
                standardSingleTenantConfigurationUsingJackson(
                     AggregateType.of("Orders"),
                     createObjectMapper(),
                     AggregateIdSerializer.serializerFor(OrderId.class),
                     IdentifierColumnType.UUID,
                     JSONColumnType.JSONB),
                 unitOfWorkFactory,
                 OrderId.class,
                 Order.class
                );
 
Here's a typical usage pattern for when you want to persist an new FlexAggregate instance (i.e. the EventStore doesn't contain an events related to the given Aggregate id):

 unitOfWorkFactory.usingUnitOfWork(unitOfWork -> {
      var eventsToPersist = Order.createNewOrder(orderId, CustomerId.random(), 123);
      repository.persist(eventsToPersist);
  });
 
Here's the typical usage pattern for FlexAggregateRepository for already existing FlexAggregate instance (i.e. an instance that has events in the EventStore):

 unitOfWorkFactory.usingUnitOfWork(unitOfWork -> {
      var order = repository.load(orderId);
      var eventsToPersist = order.accept();
      repository.persist(eventsToPersist);
  });
 
 
See Also: