-
Notifications
You must be signed in to change notification settings - Fork 12
Closed
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Right now it's not possible to use abstract projections in Spine.
E.g., following code will throw java.lang.IllegalArgumentException: org.spine3.server.event.EventDispatcherRegistry: No message types are forwarded by this dispatcher during setup of BoundedContext:
public abstract class AbstractProjection<I, M extends Message> extends Projection<I, M> {
protected AbstractImagesStatisticsProjection(I id) {
super(id);
}
@Subscribe
public void on(Event e, EventContext context) {
doSmth(e, context);
}
protected abstract void doSmth(Event e, EventContext context);
}public class Projection extend AbstractProjection<ProjectionId, ProjectionMessage>{
protected Projection(ProjectionId id) {
super(id);
}
@Override
protected void doSmth(Event e, EventContext context){
//do smth
}
}Why do we need such feature?
E.g. we have 2 projections with time IDs - one is for Daily statistics and other for Hourly statistics. They, probably will subscribe for the same events and have almost the same logic.
In order to reduce code duplication it would be great, if we could subscribe to events in abstract classes.
Current situation
The only possible way to reduce code duplication right now is to override on methods and call super inside:
public class Projection extend AbstractProjection<ProjectionId, ProjectionMessage>{
protected Projection(ProjectionId id) {
super(id);
}
@Subscribe
@Override
public void on(Event e, EventContext context) {
super(e, context);
}
@Override
protected void doSmth(Event e, EventContext context){
//do smth
}
}Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
✅ Done