I have a mono repo project that consists of two (lerna built) packages Base and Libs. I am trying to use TypeDi dependency injection and the classes marked with the Service() decorator from the Libs project are not created in the Base Container:
libs/example.js
import { Service } from 'typedi';
@Service()
export class ExampleService{
//...do stuff
}
libs/index.js
import { ExampleService } from './example';
export { ExampleService };
base/index.js
import { Container } from 'typedi';
import { ExampleService } from 'Libs'
//Error thrown here "Service with "MaybeConstructable<ExampleService>" identifier was not found in the container. Register it before usage via explicitly calling the "Container.set" function or using the "@Service()" decorator."
const xmpl = Container.get(ExampleService)
Is there any way to inject these classes without explicitly importing all the class dependencies to the Base project and using Container.set()
According to the error message
ExampleServicewas not registered.The code example lacks the required
import 'reflect-metadata';string at the entry point of your application.Add the
reflect-metadataas the first string to yourapp/server/...ts file.