I am trying to load modules as classes with the loadModules
method but then when I execute a method of a container class, it appears as if it had not been instantiated because when accessing this from the class itself it is undefined.
The name of the parameters in the constructor matches the one stored in the container and the modules are resolved correctly.
I am registering all modules as asClass
.
How can I make the class instance?
I have this container configuration. First I get the modules (all are classes) with listModules
.
export const userModules = awilix.listModules(
[
['application/*.ts', { register: awilix.asClass }],
[
'infra/prisma-user-repository.ts',
{
name: 'userRepository',
register: awilix.asClass,
lifetime: awilix.Lifetime.SINGLETON,
},
],
[
'infra/user-controller.ts',
{
register: awilix.asClass,
lifetime: awilix.Lifetime.SINGLETON,
},
],
],
{
cwd: 'src/app/user',
}
);
Then I create the container and load them:
export const container = awilix.createContainer();
container.loadModules(
userModules.map(module => [
module.path,
module.opts,
]),
{
formatName: (name, description) => {
const camelCaseName = toCamelCase(description.opts?.name || name);
return camelCaseName;
},
}
);