Skip to content

Dynamic service providers and arguments #846

Answered by andersevenrud
maryam4s26 asked this question in Q&A
Discussion options

You must be logged in to vote

I would suggest using (prefixed) environmental flags if you just want basic bootstrapping.

For example imagine you have two providers: Foo and Bar.

const enabledServices = process.env.OSJS_SERVICES.split(',')

if (enabledServices.includes('Foo')) {
  osjs.register(FooServiceProvider, {
    args: {
      arg1: process.env.OSJS_SERVICE_FOO_ARG1,
      arg2: process.env.OSJS_SERVICE_FOO_ARG2,
    }
  })
}
if (enabledServices.includes('Bar')) {
  osjs.register(BarServiceProvicer, {
    args: {
      arg1: process.env.OSJS_SERVICE_BAR_ARG1,
      arg2: process.env.OSJS_SERVICE_BAR_ARG2,
    }
  })
}

Then this could be set up with:

OSJS_SERVICES=Foo,Bar
OSJS_SERVICE_FOO_ARG1=Hello
OSJS_SERVICE_…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by andersevenrud
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #844 on March 05, 2024 23:16.