Skip to content

Commit 8721acc

Browse files
vanroguclaude
andcommitted
Move feature slice start*() calls into BoundedContext.start()
The conditional startCommand/startQuery/startAutomation/startProjection calls on deployed feature slices were duplicated in every Application class. Move this logic into BoundedContextImpl.start() using the same enable flags already passed via FeaturesSpecification, eliminating the boilerplate from all Application constructors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ef04eb2 commit 8721acc

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

sliceworkz-eventmodeling-impl/src/main/java/org/sliceworkz/eventmodeling/module/boundedcontext/BoundedContextBuilderImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,25 @@ public <T> T build ( Class<T> returnType ) {
349349
AggregateModule aggregateModule = new AggregateModule(name, instance, aggregateSpecifications, domainEventStream, meterRegistry);
350350

351351
BoundedContextImpl bc =
352-
new BoundedContextImpl(name, deployedFeatureSlices, undeployedFeatureSlices, domainEventStream, inboundEventStream, outboundEventStream, observabilityEventStream, dcb, aggregateModule, rmm, am, im, om, instance, meterRegistry, adapterRegistry);
352+
new BoundedContextImpl(name, deployedFeatureSlices, undeployedFeatureSlices,
353+
featuresSpecification.mustDeployCommands(),
354+
featuresSpecification.mustDeployQueries(),
355+
featuresSpecification.mustDeployAutomations(),
356+
featuresSpecification.mustDeployProjections(),
357+
domainEventStream, inboundEventStream, outboundEventStream, observabilityEventStream, dcb, aggregateModule, rmm, am, im, om, instance, meterRegistry, adapterRegistry);
353358

354359
// this is only possible after creation
355360
am.setCapabilitiesDelegate(bc);
356361
im.setCapabilitiesDelegate(bc);
357362

363+
T result;
358364
if ( returnType.isInterface()) {
359-
return proxy(bc, returnType);
365+
result = proxy(bc, returnType);
360366
} else {
361-
return (T)bc;
367+
result = (T)bc;
362368
}
369+
bc.setSelfReference((BoundedContext<?,?,?>) result);
370+
return result;
363371
}
364372

365373
public static <T> T proxy ( BoundedContextImpl<?,?,?> boundedContext, Class<?> interfaceClass ) {

sliceworkz-eventmodeling-impl/src/main/java/org/sliceworkz/eventmodeling/module/boundedcontext/BoundedContextImpl.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ public class BoundedContextImpl<DOMAIN_EVENT_TYPE,INBOUND_EVENT_TYPE,OUTBOUND_EV
6868

6969
private List<? extends Slice<? extends BoundedContext<?,?,?>>> deployedFeatureSlices;
7070
private List<? extends Slice<? extends BoundedContext<?,?,?>>> undeployedFeatureSlices;
71-
71+
72+
private boolean startCommands;
73+
private boolean startQueries;
74+
private boolean startAutomations;
75+
private boolean startProjections;
76+
77+
private BoundedContext<?,?,?> selfReference;
78+
7279
private String name;
7380
private Instance instance;
7481

@@ -82,6 +89,10 @@ public BoundedContextImpl (
8289
String name,
8390
List<? extends Slice<? extends BoundedContext<?,?,?>>> deployedFeatureSlices,
8491
List<? extends Slice<? extends BoundedContext<?,?,?>>> undeployedFeatureSlices,
92+
boolean startCommands,
93+
boolean startQueries,
94+
boolean startAutomations,
95+
boolean startProjections,
8596
EventStream<DOMAIN_EVENT_TYPE> domainEventStream,
8697
EventStream<INBOUND_EVENT_TYPE> inboundEventStream,
8798
EventStream<OUTBOUND_EVENT_TYPE> outboundEventStream,
@@ -100,6 +111,10 @@ public BoundedContextImpl (
100111
this.meterRegistry = meterRegistry;
101112
this.deployedFeatureSlices = deployedFeatureSlices;
102113
this.undeployedFeatureSlices = undeployedFeatureSlices;
114+
this.startCommands = startCommands;
115+
this.startQueries = startQueries;
116+
this.startAutomations = startAutomations;
117+
this.startProjections = startProjections;
103118

104119
this.domainEventStream = domainEventStream;
105120

@@ -129,13 +144,25 @@ public BoundedContextImpl (
129144
);
130145
}
131146

147+
void setSelfReference(BoundedContext<?,?,?> selfReference) {
148+
this.selfReference = selfReference;
149+
}
150+
132151
private Set<KernelEvent.FeatureSlice> map ( List<? extends Slice<? extends BoundedContext<?,?,?>>> featureSlices ) {
133152
return featureSlices.stream().map(fs->new KernelEvent.FeatureSlice(fs.name(), fs.type().name(), fs.context(), fs.chapter(), fs.tags())).collect(Collectors.toSet());
134153
}
135154

155+
@SuppressWarnings({"unchecked", "rawtypes"})
136156
@Override
137157
public void start ( ) {
138158
LOGGER.info("starting bounded context '{}' ...", name);
159+
for (var slice : deployedFeatureSlices) {
160+
Slice raw = (Slice) slice;
161+
if (startCommands) raw.startCommand(selfReference);
162+
if (startQueries) raw.startQuery(selfReference);
163+
if (startAutomations) raw.startAutomation(selfReference);
164+
if (startProjections) raw.startProjection(selfReference);
165+
}
139166
this.inboundModule.start();
140167
this.outboundModule.start();
141168
this.dcbDomainModule.start();

0 commit comments

Comments
 (0)