Skip to content

feat(container): add conditional bindings - #70

Open
RomainLanz wants to merge 1 commit into
11.xfrom
feat/conditional-bindings
Open

feat(container): add conditional bindings#70
RomainLanz wants to merge 1 commit into
11.xfrom
feat/conditional-bindings

Conversation

@RomainLanz

Copy link
Copy Markdown
Member

Hey! 👋🏻

This PR adds a new API to register conditional bindings.

Example Story: You want to try a new payment gateway and roll-out that feature only to a few users.

With the new API, you can register a conditional bindings that resolve a different class depending on a condition.

container.bind(PaymentGateway, (resolver) => {
  return resolver.make(StripePaymentGateway)
})

container.bindWhen(
  PaymentGateway,
  async (resolver) => {
    const ctx = await resolver.make(HttpContext)
    return ctx.auth.user?.featureFlags.includes('new-payment') === true
  },
  (resolver) => resolver.make(BetaPaymentGateway)
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant