GH-156 - Polish example.
Add sample documentation. Reintroduce Lombok to avoid boilerplate. Use jMolecules DDD abstractions to represent aggregates. Use Scenario API in test cases.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package example.inventory;
|
||||
|
||||
import example.order.OrderCompleted;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -28,15 +29,12 @@ import org.springframework.stereotype.Service;
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@Service
|
||||
public class InventoryManagement {
|
||||
@RequiredArgsConstructor
|
||||
class InventoryManagement {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(InventoryManagement.class);
|
||||
|
||||
final InventoryInternal dependency;
|
||||
|
||||
InventoryManagement(InventoryInternal dependency) {
|
||||
this.dependency = dependency;
|
||||
}
|
||||
private final InventoryInternal dependency;
|
||||
|
||||
@ApplicationModuleListener
|
||||
void on(OrderCompleted event) throws InterruptedException {
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
*
|
||||
* @see example.inventory.InventoryInternal
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package example.inventory;
|
||||
|
||||
@@ -15,18 +15,20 @@
|
||||
*/
|
||||
package example.order;
|
||||
|
||||
import example.order.Order.OrderIdentifier;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.jmolecules.ddd.types.AggregateRoot;
|
||||
import org.jmolecules.ddd.types.Identifier;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
public class Order {
|
||||
public class Order implements AggregateRoot<Order, OrderIdentifier> {
|
||||
|
||||
private OrderIdentifier id = new OrderIdentifier(UUID.randomUUID());
|
||||
private @Getter OrderIdentifier id = new OrderIdentifier(UUID.randomUUID());
|
||||
|
||||
public OrderIdentifier getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static record OrderIdentifier(UUID id) {}
|
||||
public static record OrderIdentifier(UUID id) implements Identifier {}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package example.order;
|
||||
|
||||
import example.order.internal.OrderInternal;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -25,16 +27,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class OrderManagement {
|
||||
|
||||
final ApplicationEventPublisher events;
|
||||
final OrderInternal dependency;
|
||||
|
||||
OrderManagement(ApplicationEventPublisher events, OrderInternal dependency) {
|
||||
|
||||
this.events = events;
|
||||
this.dependency = dependency;
|
||||
}
|
||||
private final @NonNull ApplicationEventPublisher events;
|
||||
private final @NonNull OrderInternal dependency;
|
||||
|
||||
@Transactional
|
||||
public void complete(Order order) {
|
||||
|
||||
@@ -18,7 +18,8 @@ package example.order.internal;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Some order-internal application component.
|
||||
* Some order-internal application component. Referring to it from the inventory module would be captured by
|
||||
* {@link example.ModularityTests}.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
*
|
||||
* @see example.ModularityTests
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package example.order;
|
||||
|
||||
Reference in New Issue
Block a user