Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware chain for command and querybud #1032

Closed
1 task done
JonasWijne opened this issue Jun 8, 2022 · 2 comments
Closed
1 task done

Middleware chain for command and querybud #1032

JonasWijne opened this issue Jun 8, 2022 · 2 comments
Labels

Comments

@JonasWijne
Copy link

JonasWijne commented Jun 8, 2022

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

I have a issue when i want to log all commands, lets say I have a few commands and I want to log all commands that are run for auditing.

Describe the solution you'd like

a middleware chain that can be registered onto the command or query bus.

middleware class and decorator to register (maybe with filters)

middleware class should have a handle method (like a command handler or queryhandler) that has 2 arguments
command/query and a next function

Teachability, documentation, adoption, migration strategy

small example

@Middleware()
export class LogMiddleware implements IMiddleware<any, any> {
    handle(command: ICommand, next: NextFunction): any {
        console.log(command);
        return next(command);
    }
}

What is the motivation / use case for changing the behavior?

this allows for adding functionality without changing behaviour.

@FredericEspiau
Copy link

For your information, you can already do it using the ExplorerService: https://github.com/nestjs/cqrs/blob/master/src/services/explorer.service.ts

@kamilmysliwiec
Copy link
Member

I have a issue when i want to log all commands, lets say I have a few commands and I want to log all commands that are run for auditing.

You can attach a side-effect by subscribing to the CommandBus stream. Command cannot be mutated though (and that's the desired behavior).

@nestjs nestjs locked and limited conversation to collaborators Jun 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants