-
Notifications
You must be signed in to change notification settings - Fork 1
Quick Start
Alex Chugaev edited this page Jan 10, 2021
·
2 revisions
This example demonstrates how to implement a complex save operation which includes 3 steps using CQRS.
Say, in order to perform save operation, we have to go through these steps:
- create attachments from the data list;
- save entity data (submit HTTP request with JSON payload);
- associate created attachments with the entity.
This allows access to such global services as EventBus
, CommandBus
, QueryBus
, and ErrorBus
.
import { NgModule } from '@angular/core';
import { CqrsModule } from '@ngry/cqrs';
@NgModule({
imports: [
CqrsModule.forRoot(),
]
})
export class AppModule {
}
Typically, the feature module is the one lazy-loaded when the user navigates to a certain route.
export class PrepareAttachmentsCommand {
constructor(
readonly entity: Entity,
readonly items: Array<Item>,
) {
}
}
export class SaveEntityCommand {
constructor(
readonly entity: Entity,
readonly attachments: Array<Attachment>,
) {
}
}
export class AddAttachmentsCommand {
constructor(
readonly entity: Entity,
readonly attachments: Array<Attachment>,
) {
}
}
export class FormSubmitEvent {
constructor(
readonly entity: Entity,
readonly attachments: Array<Attachment>,
) {
}
}
export class PrepareAttachmentsDoneEvent {
constructor(
readonly entity: Entity,
readonly attachments: Array<Attachment>,
) {
}
}
export class SaveEntityDoneEvent {
constructor(
readonly entity: Entity,
readonly attachments: Array<Attachment>,
) {
}
}
export class SaveAttachmentsDoneEvent {
constructor(
readonly entity: Entity,
readonly attachments: Array<Attachment>,
) {
}
}
import { NgModule } from '@angular/core';
import { CqrsModule } from '@ngry/cqrs';
@NgModule({
imports: [
CqrsModule.forFeature({
commands: [
PrepareAttachmentsHandler,
SaveEntityHandler,
SaveAttachmentsHandler,
],
events: [
SavedHandler,
],
sagas: [
SaveSaga,
],
}),
],
})
export class FeatureModule {
}
Getting Started
Documentation
- What is CQRS
- Commands and command handlers
- Queries and query handlers
- Events and event handlers
- Sagas
- Error handling
Examples