/** * Creates a new aggregate instance. In order for new aggregate to be created, a {@link Repository} should be * available to the current aggregate. {@link Repository} of an aggregate to be created is exposed to the current * aggregate via {@link RepositoryProvider}. * * @param <T> type of new aggregate to be created * @param aggregateType type of new aggregate to be created * @param factoryMethod factory method which creates new aggregate * @return a new aggregate instance * @throws Exception thrown if something goes wrong during instantiation of new aggregate */ public static <T> Aggregate<T> createNew(Class<T> aggregateType, Callable<T> factoryMethod) throws Exception { if (!isLive()) { throw new UnsupportedOperationException( "Aggregate is still initializing its state, creation of new aggregates is not possible"); } return getInstance().doCreateNew(aggregateType, factoryMethod); }