Repository navigation
1.1
The way module base packages are identified can now be customized by registering an implementation of org.moduliths.model.ModuleDetectionStrategy in spring.factories.
Reasonable default implementations to delegate to are available via ModuleDetectionStrategy.directSubPackage() (default) or ModuleDetectionStrategy.explictlyAnnotated() (which only detects packages, explicitly annotated with @Module). See the commits for #137 for details.
Also, a Modules instance can also be created from a plain package name (only by a class previously).
The previously included support for the experimental jDDD has been replaced by support for jMolecules which is to a wide extend a rebranded version of the former. The support for jDDD has been deprecated and will be removed for 1.2. Please change the package imports accordingly.
jMolecules support consists of identifying architecturally relevant components, events and DDD building blocks using either the stereotype annotations or dedicated interfaces.
-
@org.jmolecules.ddd.annotation.Service -
@org.jmolecules.ddd.annotation.Repository -
@org.jmolecules.ddd.annotation.AggregateRoot -
@org.jmolecules.ddd.annotation.Entity -
@org.jmolecules.event.annotation.DomainEvent
We now ship a moduliths-events package that hooks into Spring Framework’s event multicasting infrastructure to maintain an event publication log to be able to recover failed invocations of @TransactionalEventListener methods. See this slide deck and talk recording for more details.
The module canvas now lists Spring beans grouped by their stereotype, i.e. by their architectural role. By default, the stereotypes supported by Spring Framework are used. Also, the jMolecules equivalents are discovered. Custom groupings can be defined and passed via the CanvasOptions:
import org.moduliths.docs.Documenter.CanvasOptions.Grouping;
var dataInitializers = Grouping.of("Data initializers",
"Components to initialize dummy data on application startup.",
Grouping.subtypeOf(DataInitializer.class)); // (1)
var representations = Grouping.of("Representations",
"Components to map from domain types to DTOs and vice versa.",
Grouping.nameMatching(".*Representations")); // (2)
new Documenter(modules)
.writeModuleCanvases(CanvasOptions.defaults() // (3)
.groupingBy(representations, dataInitializers)) // (4)-
Additional grouping by type.
-
Additional grouping by name.
-
Adds the default Spring stereotype groups. Use
….withoutDefaultGroupings()to avoid this. -
Register the custom groupings.
In the Published Events section of the Module Canvas we now also list the places in the codebase that create these events. We discover invocations of static factory methods on the event type that return instances of the event type. Also, constructor invocations on the event type are discovered, except the ones originating in the event type itself.
class MyEvent implements org.jmolecules.event.types.DomainEvent {
MyEvent(…) {} // (1)
public static MyEvent of(…) { // (2)
return new MyEvent(…); // (3)
}
}
class SomeOtherClass {
void someMethod() { // (4)
new MyEvent(…); // (5)
MyEvent.of(…); // (6)
}
}-
A simple constructor (default or with parameters).
-
A factory method on the event class itself, returning instances of the event type itself.
-
A type internal constructor invocation (will not be reported).
-
someMethod()being returned as source forMyEventdue to… -
the constructor invocation from a different class
-
the factory method invocation.
Here’s the output of that on a real-world project using Moduliths:
We introduced AggregateTestUtils to obtain all events registered on an aggregate via the Spring Data event publication support in unit tests.
Also, TypedPublishedEvents now has a matchingMapped(…) method that allows to easily match events that applies a mapping function before invoking the predicate.