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

Request scope or an alternative for multitenancy, using CQRS module #1656

Open
1 task done
j3bb9z opened this issue Mar 14, 2024 · 2 comments
Open
1 task done

Request scope or an alternative for multitenancy, using CQRS module #1656

j3bb9z opened this issue Mar 14, 2024 · 2 comments
Labels

Comments

@j3bb9z
Copy link

j3bb9z commented Mar 14, 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

Normally we can do multitenancy using durable providers:
https://docs.nestjs.com/fundamentals/injection-scopes#durable-providers

However this doesn't work when using CQRS module.

There is an issue with 80 comments on this, but it's closed for discussion, with no further explanation:
#60

There is a MR, but again - without any answer:
#549

We need either request scope to work in CQRS module or any viable alternative.

Describe the solution you'd like

Either make request scoped providers work with CQRS module or providing an alternative, how to do multi-tenant applications. Creating separate query bus for every request seems too much of an overhead, but I think it's acceptable, when combined with durable providers and limited number of tenants.

Teachability, documentation, adoption, migration strategy

No response

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

We are implementing multitenancy in quite big application, with many modules that need to be configured differently, for different tenants. Unfortunately, async_hooks will not be an easy solution, since many modules are configured once, upon their creation. Request scope + durable providers seems to be simplest solution, but it doesn't work with CQRS module.

@j3bb9z j3bb9z added the feature label Mar 14, 2024
@Papooch
Copy link

Papooch commented Jul 11, 2024

If you need to use request scope with CQRS, you'd either need to play with ContextIdFactory or use an alternative like AsyncLocalStorage to propagate request context.

@j3bb9z
Copy link
Author

j3bb9z commented Jul 18, 2024

Hi, @Papooch. I'm in the process of implementing multi-tenancy using your nestjs-cls library.

Thanks a lot! 🙏

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

2 participants