1

I'm using Awilix with Typescript. This is how I'm creating container

const container = createContainer();

container.loadModules(["src/service/**/*.ts"], {
  formatName: "camelCase",

  resolverOptions: {
    injectionMode: InjectionMode.CLASSIC,
    register: asClass,
  },
});

There is only one service helloWorldService but creating container like this will not provide any safety. For example I can do this container.cradle.someBadThing typescript will not give me any error.

The only way I found is to create manually interface.

interface ICradle {
  helloWorldService: HelloWorldService;
}
const container = createContainer<ICradle>();

This works fine but problem is if you have 100's of file and you have to mention each file in interface can get boring. How we can automate this thing?

Azeem Haider
  • 1,443
  • 4
  • 23
  • 41

0 Answers0