}
addToSession(aggregate);
}
private <T extends AggregateRoot> void addToSession(T aggregate) {
AggregateRoot previous = aggregatesById.put(aggregate.getVersionedId().getId(), aggregate);
if (previous != null && previous != aggregate) {
throw new IllegalStateException("multiple instances with same id " + aggregate.getVersionedId().getId());
}
}