ryan-mars / stochastic

TypeScript framework for building event-driven services. Easily go from Event Storming → Code.
MIT License
6 stars 1 forks source link

BoundedContext: Can subscribe to events from another bounded context #20

Closed ryan-mars closed 3 years ago

ryan-mars commented 3 years ago

Some events will be emitted outside of the bounded context for others to react. We need a component that will aid the developer in describing this behavior.

Related #15, #7

// operations/src/service.ts
import { scheduling } from "scheduling/lib/index";

const SchedulingBoundedContext = new ExternalBoundedContext({
  boundedContext: scheduling,
});

const {
  ScheduledFlightAddedEvent,
  FlightCreatedEvent,
} = SchedulingBoundedContext.events;

export const FlightManagementPolicy = new Policy(
  {
    __filename,
    events: [ScheduledFlightAddedEvent, FlightCreatedEvent],
    commands: [AddFlight],
  },
  async (event, commands) => {
    // ...
  }
);

export const operations = new EventStorm({
  handler: "operations",
  name: "Operations",
  components: {
    SchedulingBoundedContext,
    FlightManagementPolicy,
    AddFlight,
  },
});