typedi icon indicating copy to clipboard operation
typedi copied to clipboard

question: using typedi multiple projects

Open Zekhap opened this issue 9 months ago • 1 comments

Right now i have my core project. Lets say it has this class.

@Service()
export class LoggerManager extends AbstractManager {}

and then my main project that is importing my core project with npm depencendy

@Service()
export class DatabaseManager extends AbstractManager {}

I have added reflect-metadata. Everything is working...in its own project.

i cant do Container.get(LoggerManager); if im in my main project but i can do Container.get(DatabaseManager);

i exported Container from my core project

console.log(MainContainer.handlers);
console.log(CoreContainer.handlers);

there i see my managers loaded, but its not in the same Container.

I tried also to do this in my core project Reflect.setMetadata('service', 'HELLO', Error);

And then i did this in my main project, it worked for me.

const metadataValue = Reflect.getMetadata('service', Error);
if (metadataValue) {
  console.log('Metadata exists:', metadataValue);
} else {
  console.log('Metadata does not exist');
}

So... i dont know what to do next.

Its telling me to ServiceNotFoundError: Service with "LoggerManager" identifier was not found in the container. Register it before usage via explicitly calling the "Container.set" function or using the "@Service()" decorator.

Zekhap avatar Feb 15 '25 18:02 Zekhap

Actually this can be my issue https://github.com/typestack/typedi/issues/942#issuecomment-1317465785

Yes each project have its own node_modules

Zekhap avatar Feb 15 '25 21:02 Zekhap