feat: Flatten the provider config for all modules (#7930)
This commit is contained in:
@@ -20,11 +20,7 @@ const moduleOptions = {
|
||||
process.cwd() +
|
||||
"/integration-tests/__fixtures__/providers/default-provider"
|
||||
),
|
||||
options: {
|
||||
config: {
|
||||
"default-provider": {},
|
||||
},
|
||||
},
|
||||
id: "default-provider",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -8,20 +8,21 @@ import {
|
||||
import { Lifetime, asFunction, asValue } from "awilix"
|
||||
|
||||
const registrationFn = async (klass, container, pluginOptions) => {
|
||||
Object.entries(pluginOptions.config || []).map(([name, config]) => {
|
||||
const key = FileProviderService.getRegistrationIdentifier(klass, name)
|
||||
const key = FileProviderService.getRegistrationIdentifier(
|
||||
klass,
|
||||
pluginOptions.id
|
||||
)
|
||||
|
||||
container.register({
|
||||
[FileProviderRegistrationPrefix + key]: asFunction(
|
||||
(cradle) => new klass(cradle, config),
|
||||
{
|
||||
lifetime: klass.LIFE_TIME || Lifetime.SINGLETON,
|
||||
}
|
||||
),
|
||||
})
|
||||
|
||||
container.registerAdd(FileProviderIdentifierRegistrationName, asValue(key))
|
||||
container.register({
|
||||
[FileProviderRegistrationPrefix + key]: asFunction(
|
||||
(cradle) => new klass(cradle, pluginOptions.options ?? {}),
|
||||
{
|
||||
lifetime: klass.LIFE_TIME || Lifetime.SINGLETON,
|
||||
}
|
||||
),
|
||||
})
|
||||
|
||||
container.registerAdd(FileProviderIdentifierRegistrationName, asValue(key))
|
||||
}
|
||||
|
||||
export default async ({
|
||||
|
||||
@@ -17,11 +17,13 @@ export type FileModuleOptions = Partial<ModuleServiceInitializeOptions> & {
|
||||
* The module provider to be registered
|
||||
*/
|
||||
resolve: string | ModuleProviderExports
|
||||
options: {
|
||||
/**
|
||||
* key value pair of the provider name and the configuration to be passed to the provider constructor
|
||||
*/
|
||||
config: Record<string, unknown>
|
||||
}
|
||||
/**
|
||||
* The id of the provider
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* key value pair of the configuration to be passed to the provider constructor
|
||||
*/
|
||||
options?: Record<string, unknown>
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user