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

Support for Request Scoped/Durable Providers #1685

Open
1 task done
petrusdemelo opened this issue Apr 15, 2024 · 1 comment
Open
1 task done

Support for Request Scoped/Durable Providers #1685

petrusdemelo opened this issue Apr 15, 2024 · 1 comment
Labels

Comments

@petrusdemelo
Copy link

petrusdemelo commented Apr 15, 2024

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

Currently the nestjs/cqrs doesn't support request scoped dependencies into the handlers. Thus, if a @CommandHandler provider depends on another provider marked as Request Scoped, this provider comes as undefined. That also impacts multi-tenancy applications.

Describe the solution you'd like

pseudocode

public async execute<TCommand extends ICommand, TResult extends IResult>(command: TCommand): Promise<TResult> {
	const commandName = command.constructor.name;
	let handler = this.commandRegister.getHandlerSingleton(commandName);

	if (!handler) {
		const handlerType = this.commandRegister.getHandlerType(commandName);
		const contextId = ContextIdFactory.getByRequest(this.request);
		if (handlerType) {
			this.moduleRef.registerRequestByContextId(
				{ ... this.context },
				contextId,
			);
			handler = await this.moduleRef.resolve(handlerType, contextId, { strict: false });
		}
	}

	if (!handler) {
		throw new Error(`Command handler not found for ${commandName}`);
	}

	return handler.execute(command);
}

I know there is the commandId instead of commandName to identify the commands. This is just an a example.

Teachability, documentation, adoption, migration strategy

Send a pull request that handles with the instantiation of the handlers request scoped and respect the strategy applied ContextIdFactory

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

Use nestjs/cqrs in a multi tenancy application.

@petrusdemelo
Copy link
Author

petrusdemelo commented Apr 15, 2024

I spent the weekend looking into the discussions and proposed implementations below as well as reading the nestjs/cqrs codebase.

#60
#549

And I'm able to create and send a pull request to contribute to this. However, the last PR hung for three years without merging. I'd like to understand if it's worthwhile to move on with the contribution or if it's something that I should wait for other contributors.

I wouldn't want to open a PR and close after three years as the last person did.

I implemented my own version of the feature and I'm using it currently in the place of nestjs/cqrs. But I want to become a contributor so I imagine this is a good opportunity.

I created this new issue because I'm not able to answer the mentioned one.

@petrusdemelo petrusdemelo changed the title Enable multi tenancy support with Request Scoped/Durable Providers Support with Request Scoped/Durable Providers Apr 15, 2024
@petrusdemelo petrusdemelo changed the title Support with Request Scoped/Durable Providers Support for Request Scoped/Durable Providers Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant